| 259 | } |
| 260 | |
| 261 | func TestLessOrEqual(t *testing.T) { |
| 262 | mockT := new(testing.T) |
| 263 | |
| 264 | if !LessOrEqual(mockT, 1, 2) { |
| 265 | t.Error("LessOrEqual should return true") |
| 266 | } |
| 267 | |
| 268 | if !LessOrEqual(mockT, 1, 1) { |
| 269 | t.Error("LessOrEqual should return true") |
| 270 | } |
| 271 | |
| 272 | if LessOrEqual(mockT, 2, 1) { |
| 273 | t.Error("LessOrEqual should return false") |
| 274 | } |
| 275 | |
| 276 | // Check error report |
| 277 | for _, currCase := range []struct { |
| 278 | less interface{} |
| 279 | greater interface{} |
| 280 | msg string |
| 281 | }{ |
| 282 | {less: "a", greater: "b", msg: `"b" is not less than or equal to "a"`}, |
| 283 | {less: int(1), greater: int(2), msg: `"2" is not less than or equal to "1"`}, |
| 284 | {less: int8(1), greater: int8(2), msg: `"2" is not less than or equal to "1"`}, |
| 285 | {less: int16(1), greater: int16(2), msg: `"2" is not less than or equal to "1"`}, |
| 286 | {less: int32(1), greater: int32(2), msg: `"2" is not less than or equal to "1"`}, |
| 287 | {less: int64(1), greater: int64(2), msg: `"2" is not less than or equal to "1"`}, |
| 288 | {less: uint8(1), greater: uint8(2), msg: `"2" is not less than or equal to "1"`}, |
| 289 | {less: uint16(1), greater: uint16(2), msg: `"2" is not less than or equal to "1"`}, |
| 290 | {less: uint32(1), greater: uint32(2), msg: `"2" is not less than or equal to "1"`}, |
| 291 | {less: uint64(1), greater: uint64(2), msg: `"2" is not less than or equal to "1"`}, |
| 292 | {less: float32(1.23), greater: float32(2.34), msg: `"2.34" is not less than or equal to "1.23"`}, |
| 293 | {less: float64(1.23), greater: float64(2.34), msg: `"2.34" is not less than or equal to "1.23"`}, |
| 294 | {less: uintptr(1), greater: uintptr(2), msg: `"2" is not less than or equal to "1"`}, |
| 295 | {less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 01:00:00 +0000 UTC" is not less than or equal to "0001-01-01 00:00:00 +0000 UTC"`}, |
| 296 | {less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 2]" is not less than or equal to "[1 1]"`}, |
| 297 | } { |
| 298 | out := &outputT{buf: bytes.NewBuffer(nil)} |
| 299 | False(t, LessOrEqual(out, currCase.greater, currCase.less)) |
| 300 | Contains(t, out.buf.String(), currCase.msg) |
| 301 | Contains(t, out.helpers, "github.com/expr-lang/expr/internal/testify/assert.LessOrEqual") |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func TestPositive(t *testing.T) { |
| 306 | mockT := new(testing.T) |