Skip to content

Commit

Permalink
tpl/compare: Fix eq when > 2 args
Browse files Browse the repository at this point in the history
Fixes #6786
  • Loading branch information
bep committed Jan 23, 2020
1 parent 0c251be commit 2fefc01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tpl/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ func (n *Namespace) Eq(first interface{}, others ...interface{}) bool {
normFirst := normalize(first)
for _, other := range others {
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 {
return e.Eq(first)
if e.Eq(first) {
return true
}
continue
}

other = normalize(other)
Expand Down
3 changes: 3 additions & 0 deletions tpl/compare/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ func TestEqualExtend(t *testing.T) {
{1, []interface{}{1, 2}, true},
{1, []interface{}{2, 1}, true},
{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...)
Expand Down

0 comments on commit 2fefc01

Please sign in to comment.