tpl/compare: Fix eq when > 2 args

Fixes #6786
This commit is contained in:
Bjørn Erik Pedersen 2020-01-23 10:48:28 +01:00
parent 0c251be66b
commit 2fefc01606
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 11 additions and 2 deletions

View file

@ -119,11 +119,17 @@ func (n *Namespace) Eq(first interface{}, others ...interface{}) bool {
normFirst := normalize(first) normFirst := normalize(first)
for _, other := range others { for _, other := range others {
if e, ok := first.(compare.Eqer); ok { if e, ok := first.(compare.Eqer); ok {
return e.Eq(other) if e.Eq(other) {
return true
}
continue
} }
if e, ok := other.(compare.Eqer); ok { if e, ok := other.(compare.Eqer); ok {
return e.Eq(first) if e.Eq(first) {
return true
}
continue
} }
other = normalize(other) other = normalize(other)

View file

@ -275,6 +275,9 @@ func TestEqualExtend(t *testing.T) {
{1, []interface{}{1, 2}, true}, {1, []interface{}{1, 2}, true},
{1, []interface{}{2, 1}, true}, {1, []interface{}{2, 1}, true},
{1, []interface{}{2, 3}, false}, {1, []interface{}{2, 3}, false},
{tstEqerType1("a"), []interface{}{tstEqerType1("a"), tstEqerType1("b")}, true},
{tstEqerType1("a"), []interface{}{tstEqerType1("b"), tstEqerType1("a")}, true},
{tstEqerType1("a"), []interface{}{tstEqerType1("b"), tstEqerType1("c")}, false},
} { } {
result := ns.Eq(test.first, test.others...) result := ns.Eq(test.first, test.others...)