diff options
author | Cameron Moore <moorereason@gmail.com> | 2017-05-20 11:54:13 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-08 21:01:15 +0200 |
commit | 204c3a9e32fcf6617ede978e35d3e2e89a5b491c (patch) | |
tree | fc07c18b7c5005356fcb8acff977cd4d789f0e5b /tpl/collections/collections_test.go | |
parent | fe901b81191860b60e6fcb29f8ebf87baef2ee79 (diff) |
tpl/collections: Support interfaces in union
Fixes #3411
Diffstat (limited to 'tpl/collections/collections_test.go')
-rw-r--r-- | tpl/collections/collections_test.go | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 9943f439e..811cb4c87 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -571,21 +571,45 @@ func TestUnion(t *testing.T) { expect interface{} isErr bool }{ + {nil, nil, []interface{}{}, false}, + {nil, []string{"a", "b"}, []string{"a", "b"}, false}, + {[]string{"a", "b"}, nil, []string{"a", "b"}, false}, + + // []A ∪ []B + {[]string{"1", "2"}, []int{3}, []string{}, false}, + {[]int{1, 2}, []string{"1", "2"}, []int{}, false}, + + // []T ∪ []T {[]string{"a", "b", "c", "c"}, []string{"a", "b", "b"}, []string{"a", "b", "c"}, false}, {[]string{"a", "b"}, []string{"a", "b", "c"}, []string{"a", "b", "c"}, false}, {[]string{"a", "b", "c"}, []string{"d", "e"}, []string{"a", "b", "c", "d", "e"}, false}, {[]string{}, []string{}, []string{}, false}, - {[]string{"a", "b"}, nil, []string{"a", "b"}, false}, - {nil, []string{"a", "b"}, []string{"a", "b"}, false}, - {nil, nil, make([]interface{}, 0), true}, - {[]string{"1", "2"}, []int{1, 2}, make([]string, 0), false}, - {[]int{1, 2}, []string{"1", "2"}, make([]int, 0), false}, {[]int{1, 2, 3}, []int{3, 4, 5}, []int{1, 2, 3, 4, 5}, false}, {[]int{1, 2, 3}, []int{1, 2, 3}, []int{1, 2, 3}, false}, {[]int{1, 2, 4}, []int{2, 4}, []int{1, 2, 4}, false}, {[]int{2, 4}, []int{1, 2, 4}, []int{2, 4, 1}, false}, {[]int{1, 2, 4}, []int{3, 6}, []int{1, 2, 4, 3, 6}, false}, {[]float64{2.2, 4.4}, []float64{1.1, 2.2, 4.4}, []float64{2.2, 4.4, 1.1}, false}, + {[]interface{}{"a", "b", "c", "c"}, []interface{}{"a", "b", "b"}, []interface{}{"a", "b", "c"}, false}, + + // []T ∪ []interface{} + {[]string{"1", "2"}, []interface{}{"9"}, []string{"1", "2", "9"}, false}, + {[]int{2, 4}, []interface{}{1, 2, 4}, []int{2, 4, 1}, false}, + {[]int8{2, 4}, []interface{}{int8(1), int8(2), int8(4)}, []int8{2, 4, 1}, false}, + {[]int8{2, 4}, []interface{}{1, 2, 4}, []int8{2, 4, 1}, false}, + {[]int16{2, 4}, []interface{}{1, 2, 4}, []int16{2, 4, 1}, false}, + {[]int32{2, 4}, []interface{}{1, 2, 4}, []int32{2, 4, 1}, false}, + {[]int64{2, 4}, []interface{}{1, 2, 4}, []int64{2, 4, 1}, false}, + {[]float64{2.2, 4.4}, []interface{}{1.1, 2.2, 4.4}, []float64{2.2, 4.4, 1.1}, false}, + {[]float32{2.2, 4.4}, []interface{}{1.1, 2.2, 4.4}, []float32{2.2, 4.4, 1.1}, false}, + + // []interface{} ∪ []T + {[]interface{}{"a", "b", "c", "c"}, []string{"a", "b", "b"}, []interface{}{"a", "b", "c"}, false}, + {[]interface{}{}, []string{}, []interface{}{}, false}, + {[]interface{}{1, 2}, []int{2, 3}, []interface{}{1, 2, 3}, false}, + {[]interface{}{1, 2}, []int8{2, 3}, []interface{}{1, 2, int8(3)}, false}, + {[]interface{}{1.1, 2.2}, []float64{2.2, 3.3}, []interface{}{1.1, 2.2, 3.3}, false}, + // errors {"not array or slice", []string{"a"}, false, true}, {[]string{"a"}, "not array or slice", false, true}, |