mirror of
https://github.com/danog/liquid.git
synced 2024-11-30 08:39:01 +01:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package evaluator
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var eqTestObj = struct{ a, b int }{1, 2}
|
|
var eqArrayTestObj = [2]int{1, 2}
|
|
|
|
var eqTests = []struct {
|
|
a, b interface{}
|
|
expected bool
|
|
}{
|
|
{nil, nil, true},
|
|
{nil, 1, false},
|
|
{1, nil, false},
|
|
{false, false, true},
|
|
{false, true, false},
|
|
{0, 1, false},
|
|
{1, 1, true},
|
|
{1.0, 1.0, true},
|
|
{1, 1.0, true},
|
|
{1, 2.0, false},
|
|
{1.0, 1, true},
|
|
{"a", "b", false},
|
|
{"a", "a", true},
|
|
{int8(2), int16(2), true}, // TODO
|
|
// {uint8(2), int8(2), true}, // FIXME
|
|
{eqArrayTestObj, eqArrayTestObj[:], true},
|
|
{[]string{"a"}, []string{"a"}, true},
|
|
{[]string{"a"}, []string{"a", "b"}, false},
|
|
{[]string{"a", "b"}, []string{"a"}, false},
|
|
{[]string{"a", "b"}, []string{"a", "b"}, true},
|
|
{[]string{"a", "b"}, []string{"a", "c"}, false},
|
|
{[]interface{}{1.0, 2}, []interface{}{1, 2.0}, true},
|
|
{eqTestObj, eqTestObj, true},
|
|
}
|
|
|
|
func TestEqual(t *testing.T) {
|
|
for i, test := range eqTests {
|
|
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
|
|
value := Equal(test.a, test.b)
|
|
require.Equalf(t, test.expected, value, "%#v == %#v", test.a, test.b)
|
|
})
|
|
}
|
|
}
|