github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/remove_value_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  func TestRemoveValue(t *testing.T) {
    14  	Convey("Should return a copy of an array without given element(s)", t, func() {
    15  		arr := values.NewArrayWith(
    16  			values.NewInt(1),
    17  			values.NewInt(2),
    18  			values.NewInt(3),
    19  			values.NewInt(4),
    20  			values.NewInt(3),
    21  		)
    22  
    23  		out, err := arrays.RemoveValue(context.Background(), arr, values.NewInt(3))
    24  
    25  		So(err, ShouldBeNil)
    26  		So(out.String(), ShouldEqual, "[1,2,4]")
    27  	})
    28  
    29  	Convey("Should return a copy of an array without given element(s) with limit", t, func() {
    30  		arr := values.NewArrayWith(
    31  			values.NewInt(1),
    32  			values.NewInt(2),
    33  			values.NewInt(3),
    34  			values.NewInt(4),
    35  			values.NewInt(3),
    36  			values.NewInt(5),
    37  			values.NewInt(3),
    38  		)
    39  
    40  		out, err := arrays.RemoveValue(
    41  			context.Background(),
    42  			arr,
    43  			values.NewInt(3),
    44  			values.Int(2),
    45  		)
    46  
    47  		So(err, ShouldBeNil)
    48  		So(out.String(), ShouldEqual, "[1,2,4,5,3]")
    49  	})
    50  }