github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/append_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/collections"
    10  	"github.com/MontFerret/ferret/pkg/runtime/values"
    11  	"github.com/MontFerret/ferret/pkg/stdlib/arrays"
    12  )
    13  
    14  func TestAppend(t *testing.T) {
    15  	Convey("Should return a copy of an array", t, func() {
    16  		arr := values.NewArrayWith(
    17  			values.NewInt(1),
    18  			values.NewInt(2),
    19  			values.NewInt(3),
    20  			values.NewInt(4),
    21  			values.NewInt(5),
    22  		)
    23  
    24  		out, err := arrays.Append(context.Background(), arr, values.NewInt(6))
    25  
    26  		So(err, ShouldBeNil)
    27  		So(out, ShouldNotEqual, arr)
    28  		So(out.(collections.Measurable).Length(), ShouldBeGreaterThan, arr.Length())
    29  	})
    30  
    31  	Convey("Should ignore non-unique items", t, func() {
    32  		arr := values.NewArrayWith(
    33  			values.NewInt(1),
    34  			values.NewInt(2),
    35  			values.NewInt(3),
    36  			values.NewInt(4),
    37  			values.NewInt(5),
    38  		)
    39  
    40  		out, err := arrays.Append(context.Background(), arr, values.NewInt(5), values.True)
    41  
    42  		So(err, ShouldBeNil)
    43  		So(out, ShouldNotEqual, arr)
    44  		So(out.(collections.Measurable).Length(), ShouldEqual, arr.Length())
    45  
    46  		out2, err := arrays.Append(context.Background(), arr, values.NewInt(6), values.True)
    47  
    48  		So(err, ShouldBeNil)
    49  		So(out2, ShouldNotEqual, arr)
    50  		So(out2.(collections.Measurable).Length(), ShouldBeGreaterThan, arr.Length())
    51  	})
    52  }