1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-19 21:28:32 +02:00
ferret/pkg/stdlib/arrays/union_test.go
Tim Voronov 24d8eedd4c
Feature/doc markup (#543)
* Added release notes

* #509 fixedOCOD typo

* Updated values

* Updated comments

* Changed stdlib docs format

* Changed format of array in docs

* Use 'any' instead of 'value' in docs

* New format for optional params

* Updated docs for testing package

* Added namespace information
2020-08-07 21:49:29 -04:00

53 lines
1.1 KiB
Go

package arrays_test
import (
"context"
"testing"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/arrays"
. "github.com/smartystreets/goconvey/convey"
)
// TestUnion returns the union of distinct values of all passed arrays.
// @param arrays {Any[], repeated} - List of arrays to combine.
// @return {Any[]} - All array elements combined in a single array, without duplicates, in any order.
func TestUnion(t *testing.T) {
Convey("Should union all arrays", t, func() {
arr1 := values.NewArrayWith(
values.NewInt(1),
values.NewInt(2),
values.NewInt(3),
values.NewInt(4),
)
arr2 := values.NewArrayWith(
values.NewString("a"),
values.NewString("b"),
values.NewString("c"),
values.NewString("d"),
)
arr3 := values.NewArrayWith(
values.NewArrayWith(
values.NewInt(1),
values.NewInt(2),
),
values.NewArrayWith(
values.NewInt(3),
values.NewInt(4),
),
)
out, err := arrays.Union(
context.Background(),
arr1,
arr2,
arr3,
)
So(err, ShouldBeNil)
So(out.String(), ShouldEqual, `[1,2,3,4,"a","b","c","d",[1,2],[3,4]]`)
})
}