Support unComparable args of uniq/complement/in

Fixes #6105
This commit is contained in:
satotake
2020-03-09 21:32:38 +09:00
committed by GitHub
parent c4fa2f0799
commit 8279d2e227
6 changed files with 30 additions and 24 deletions

View File

@@ -348,6 +348,9 @@ func TestIn(t *testing.T) {
// template.HTML
{template.HTML("this substring should be found"), "substring", true},
{template.HTML("this substring should not be found"), "subseastring", false},
// Uncomparable, use hashstructure
{[]string{"a", "b"}, []string{"a", "b"}, false},
{[][]string{{"a", "b"}}, []string{"a", "b"}, true},
} {
errMsg := qt.Commentf("[%d] %v", i, test)
@@ -356,10 +359,6 @@ func TestIn(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Assert(result, qt.Equals, test.expect, errMsg)
}
// Slices are not comparable
_, err := ns.In([]string{"a", "b"}, []string{"a", "b"})
c.Assert(err, qt.Not(qt.IsNil))
}
type testPage struct {
@@ -835,9 +834,14 @@ func TestUniq(t *testing.T) {
// Structs
{pagesVals{p3v, p2v, p3v, p2v}, pagesVals{p3v, p2v}, false},
// not Comparable(), use hashstruscture
{[]map[string]int{
{"K1": 1}, {"K2": 2}, {"K1": 1}, {"K2": 1},
}, []map[string]int{
{"K1": 1}, {"K2": 2}, {"K2": 1},
}, false},
// should fail
// uncomparable types
{[]map[string]int{{"K1": 1}}, []map[string]int{{"K2": 2}, {"K2": 2}}, true},
{1, 1, true},
{"foo", "fo", true},
} {