1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-11 19:49:44 +01:00
liquid/values/compare_test.go

50 lines
1.1 KiB
Go
Raw Normal View History

2017-07-28 00:11:37 +02:00
package values
2017-07-15 18:13:07 +02:00
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)
})
}
}