| 171 | } |
| 172 | |
| 173 | func TestGreaterOrEqual(t *testing.T) { |
| 174 | mockT := new(testing.T) |
| 175 | |
| 176 | if !GreaterOrEqual(mockT, 2, 1) { |
| 177 | t.Error("GreaterOrEqual should return true") |
| 178 | } |
| 179 | |
| 180 | if !GreaterOrEqual(mockT, 1, 1) { |
| 181 | t.Error("GreaterOrEqual should return true") |
| 182 | } |
| 183 | |
| 184 | if GreaterOrEqual(mockT, 1, 2) { |
| 185 | t.Error("GreaterOrEqual should return false") |
| 186 | } |
| 187 | |
| 188 | // Check error report |
| 189 | for _, currCase := range []struct { |
| 190 | less interface{} |
| 191 | greater interface{} |
| 192 | msg string |
| 193 | }{ |
| 194 | {less: "a", greater: "b", msg: `"a" is not greater than or equal to "b"`}, |
| 195 | {less: int(1), greater: int(2), msg: `"1" is not greater than or equal to "2"`}, |
| 196 | {less: int8(1), greater: int8(2), msg: `"1" is not greater than or equal to "2"`}, |
| 197 | {less: int16(1), greater: int16(2), msg: `"1" is not greater than or equal to "2"`}, |
| 198 | {less: int32(1), greater: int32(2), msg: `"1" is not greater than or equal to "2"`}, |
| 199 | {less: int64(1), greater: int64(2), msg: `"1" is not greater than or equal to "2"`}, |
| 200 | {less: uint8(1), greater: uint8(2), msg: `"1" is not greater than or equal to "2"`}, |
| 201 | {less: uint16(1), greater: uint16(2), msg: `"1" is not greater than or equal to "2"`}, |
| 202 | {less: uint32(1), greater: uint32(2), msg: `"1" is not greater than or equal to "2"`}, |
| 203 | {less: uint64(1), greater: uint64(2), msg: `"1" is not greater than or equal to "2"`}, |
| 204 | {less: float32(1.23), greater: float32(2.34), msg: `"1.23" is not greater than or equal to "2.34"`}, |
| 205 | {less: float64(1.23), greater: float64(2.34), msg: `"1.23" is not greater than or equal to "2.34"`}, |
| 206 | {less: uintptr(1), greater: uintptr(2), msg: `"1" is not greater than or equal to "2"`}, |
| 207 | {less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 00:00:00 +0000 UTC" is not greater than or equal to "0001-01-01 01:00:00 +0000 UTC"`}, |
| 208 | {less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 1]" is not greater than or equal to "[1 2]"`}, |
| 209 | } { |
| 210 | out := &outputT{buf: bytes.NewBuffer(nil)} |
| 211 | False(t, GreaterOrEqual(out, currCase.less, currCase.greater)) |
| 212 | Contains(t, out.buf.String(), currCase.msg) |
| 213 | Contains(t, out.helpers, "github.com/expr-lang/expr/internal/testify/assert.GreaterOrEqual") |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func TestLess(t *testing.T) { |
| 218 | mockT := new(testing.T) |