Skip to content

Commit b82cd82

Browse files
moorereasonbep
authored andcommitted
tpl/collections: Add uint support to In
1 parent 204c3a9 commit b82cd82

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

‎tpl/collections/collections.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ func (ns *Namespace) In(l interface{}, v interface{}) bool {
261261
return true
262262
}
263263
}
264+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
265+
switch vv.Kind() {
266+
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
267+
if vv.Uint() == lvv.Uint() {
268+
return true
269+
}
270+
}
264271
case reflect.Float32, reflect.Float64:
265272
switch vv.Kind() {
266273
case reflect.Float32, reflect.Float64:
@@ -564,7 +571,6 @@ func (ns *Namespace) Union(l1, l2 interface{}) (interface{}, error) {
564571
if l1v.Type() != l2v.Type() &&
565572
l1v.Type().Elem().Kind() != reflect.Interface &&
566573
l2v.Type().Elem().Kind() != reflect.Interface {
567-
568574
return r.Interface(), nil
569575
}
570576

‎tpl/collections/collections_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func TestIntersect(t *testing.T) {
298298
{[]interface{}{int16(1), int16(2), int16(3)}, []int16{1, 2, 2}, []interface{}{int16(1), int16(2)}},
299299
{[]interface{}{int32(1), int32(2), int32(3)}, []int32{1, 2, 2}, []interface{}{int32(1), int32(2)}},
300300
{[]interface{}{int64(1), int64(2), int64(3)}, []int64{1, 2, 2}, []interface{}{int64(1), int64(2)}},
301+
{[]interface{}{uint(1), uint(2), uint(3)}, []uint{1, 2, 2}, []interface{}{uint(1), uint(2)}},
301302
{[]interface{}{float32(1), float32(2), float32(3)}, []float32{1, 2, 2}, []interface{}{float32(1), float32(2)}},
302303
{[]interface{}{float64(1), float64(2), float64(3)}, []float64{1, 2, 2}, []interface{}{float64(1), float64(2)}},
303304

@@ -604,10 +605,11 @@ func TestUnion(t *testing.T) {
604605
{[]float32{2.2, 4.4}, []interface{}{1.1, 2.2, 4.4}, []float32{2.2, 4.4, 1.1}, false},
605606

606607
// []interface{} ∪ []T
607-
{[]interface{}{"a", "b", "c", "c"}, []string{"a", "b", "b"}, []interface{}{"a", "b", "c"}, false},
608+
{[]interface{}{"a", "b", "c", "c"}, []string{"a", "b", "d"}, []interface{}{"a", "b", "c", "d"}, false},
608609
{[]interface{}{}, []string{}, []interface{}{}, false},
609610
{[]interface{}{1, 2}, []int{2, 3}, []interface{}{1, 2, 3}, false},
610611
{[]interface{}{1, 2}, []int8{2, 3}, []interface{}{1, 2, int8(3)}, false},
612+
{[]interface{}{uint(1), uint(2)}, []uint{2, 3}, []interface{}{uint(1), uint(2), uint(3)}, false},
611613
{[]interface{}{1.1, 2.2}, []float64{2.2, 3.3}, []interface{}{1.1, 2.2, 3.3}, false},
612614

613615
// errors

0 commit comments

Comments
 (0)