1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 03:14:39 +01:00
liquid/generics/generics_test.go

61 lines
1.0 KiB
Go
Raw Normal View History

2017-06-28 03:30:47 +02:00
package generics
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
2017-06-28 04:54:27 +02:00
var eqTests = []struct {
a, b interface{}
expected bool
}{
{0, 1, false},
{1, 1, true},
{1.0, 1.0, true},
{"a", "b", false},
{"a", "a", true},
{nil, nil, true},
{nil, 1, false},
{1, nil, false},
{false, false, true},
{false, true, false},
}
var lessTests = []struct {
2017-06-28 03:30:47 +02:00
a, b interface{}
expected bool
}{
{0, 1, true},
{1, 0, false},
{1, 1, false},
{1, 2.0, true},
{1.0, 2, true},
{2.0, 1, false},
{"a", "b", true},
{"b", "a", false},
{nil, nil, false},
{nil, 1, true},
{1, nil, false},
{false, true, true},
}
2017-06-28 04:54:27 +02:00
func TestEqual(t *testing.T) {
for i, test := range eqTests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
value := Equal(test.a, test.b)
require.Equalf(t, test.expected, value, "%v < %v", test.a, test.b)
})
}
}
2017-06-28 03:30:47 +02:00
func TestLess(t *testing.T) {
2017-06-28 04:54:27 +02:00
for i, test := range lessTests {
2017-06-28 03:30:47 +02:00
t.Run(fmt.Sprint(i), func(t *testing.T) {
value := Less(test.a, test.b)
require.Equalf(t, test.expected, value, "%v < %v", test.a, test.b)
})
}
}