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