-
Notifications
You must be signed in to change notification settings - Fork 52
/
comp_test.go
70 lines (54 loc) · 1.9 KB
/
comp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jsonlogic
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than#string_to_string_comparison
func TestLessCompareStringToString(t *testing.T) {
assert.True(t, less("a", "b"))
assert.False(t, less("a", "a"))
assert.False(t, less("a", "3"))
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than#string_to_number_comparison
func TestLessCompareStringToNumber(t *testing.T) {
assert.False(t, less("5", 3))
assert.False(t, less("3", 3))
assert.True(t, less("3", 5))
assert.False(t, less("hello", 5))
assert.False(t, less(5, "hello"))
//console.log("5" < 3n); // false
//console.log("3" < 5n); // true
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than#number_to_number_comparison
func TestLessCompareNumberToNumber(t *testing.T) {
assert.False(t, less(5, 3))
assert.False(t, less(3, 3))
assert.True(t, less(3, 5))
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than#comparing_boolean_null_undefined_nan
func TestLessCompareBooleanNullUndefinedNan(t *testing.T) {
assert.False(t, less(true, false))
assert.True(t, less(false, true))
assert.True(t, less(0, true))
assert.False(t, less(true, 1))
assert.False(t, less(nil, 0))
assert.True(t, less(nil, 1))
assert.False(t, less(undefinedType{}, 3))
assert.False(t, less(3, undefinedType{}))
assert.False(t, less(3, math.NaN()))
assert.False(t, less(math.NaN(), 3))
}
func TestLessCompareStringAndNil(t *testing.T) {
assert.False(t, less("a", nil))
}
func TestLessCompareNumberAndNil(t *testing.T) {
assert.False(t, less(12, nil))
}
func TestEqualsWithBooleans(t *testing.T) {
assert.True(t, equals(true, true))
}
func TestEqualsWithNil(t *testing.T) {
assert.True(t, equals(nil, nil))
assert.False(t, equals(nil, ""))
}