github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/union_test.go (about) 1 package arrays_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/values" 10 "github.com/MontFerret/ferret/pkg/stdlib/arrays" 11 ) 12 13 // TestUnion returns the union of distinct values of all passed arrays. 14 // @param arrays {Any[], repeated} - List of arrays to combine. 15 // @return {Any[]} - All array elements combined in a single array, without duplicates, in any order. 16 func TestUnion(t *testing.T) { 17 Convey("Should union all arrays", t, func() { 18 arr1 := values.NewArrayWith( 19 values.NewInt(1), 20 values.NewInt(2), 21 values.NewInt(3), 22 values.NewInt(4), 23 ) 24 25 arr2 := values.NewArrayWith( 26 values.NewString("a"), 27 values.NewString("b"), 28 values.NewString("c"), 29 values.NewString("d"), 30 ) 31 32 arr3 := values.NewArrayWith( 33 values.NewArrayWith( 34 values.NewInt(1), 35 values.NewInt(2), 36 ), 37 values.NewArrayWith( 38 values.NewInt(3), 39 values.NewInt(4), 40 ), 41 ) 42 43 out, err := arrays.Union( 44 context.Background(), 45 arr1, 46 arr2, 47 arr3, 48 ) 49 50 So(err, ShouldBeNil) 51 So(out.String(), ShouldEqual, `[1,2,3,4,"a","b","c","d",[1,2],[3,4]]`) 52 }) 53 }