github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/arrays/nth_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 TestNth(t *testing.T) { 14 Convey("Should return item by index", 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(5), 21 ) 22 23 out, err := arrays.Nth(context.Background(), arr, values.NewInt(1)) 24 25 So(err, ShouldBeNil) 26 So(out.Compare(values.NewInt(2)), ShouldEqual, 0) 27 }) 28 29 Convey("Should return None when no value", t, func() { 30 arr := values.NewArrayWith() 31 32 out, err := arrays.Nth(context.Background(), arr, values.NewInt(1)) 33 34 So(err, ShouldBeNil) 35 So(out.Compare(values.None), ShouldEqual, 0) 36 }) 37 38 Convey("Should return None when passed negative value", t, func() { 39 arr := values.NewArrayWith() 40 41 out, err := arrays.Nth(context.Background(), arr, values.NewInt(-1)) 42 43 So(err, ShouldBeNil) 44 So(out.Compare(values.None), ShouldEqual, 0) 45 }) 46 }