github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/sorted_unique_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 TestSortedUnique(t *testing.T) {
    14  	Convey("Should sort numbers", t, func() {
    15  		arr := values.NewArrayWith(
    16  			values.NewInt(3),
    17  			values.NewInt(4),
    18  			values.NewInt(5),
    19  			values.NewInt(1),
    20  			values.NewInt(6),
    21  			values.NewInt(2),
    22  			values.NewInt(6),
    23  			values.NewInt(5),
    24  			values.NewInt(1),
    25  			values.NewInt(4),
    26  		)
    27  
    28  		out, err := arrays.SortedUnique(context.Background(), arr)
    29  
    30  		So(err, ShouldBeNil)
    31  		So(out.String(), ShouldEqual, "[1,2,3,4,5,6]")
    32  	})
    33  
    34  	Convey("Should sort strings", t, func() {
    35  		arr := values.NewArrayWith(
    36  			values.NewString("e"),
    37  			values.NewString("b"),
    38  			values.NewString("a"),
    39  			values.NewString("c"),
    40  			values.NewString("a"),
    41  			values.NewString("d"),
    42  			values.NewString("f"),
    43  			values.NewString("d"),
    44  			values.NewString("e"),
    45  			values.NewString("f"),
    46  		)
    47  
    48  		out, err := arrays.SortedUnique(context.Background(), arr)
    49  
    50  		So(err, ShouldBeNil)
    51  		So(out.String(), ShouldEqual, `["a","b","c","d","e","f"]`)
    52  	})
    53  
    54  	Convey("Should return empty array", t, func() {
    55  		arr := values.NewArrayWith()
    56  
    57  		out, err := arrays.SortedUnique(context.Background(), arr)
    58  
    59  		So(err, ShouldBeNil)
    60  		So(out.String(), ShouldEqual, `[]`)
    61  	})
    62  }