1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/stdlib/collections/reverse_test.go
Tim Voronov 376ad77404
Feature/#250 wait style (#255)
* Added support for parsed styles

* Added stdlib function.

* Added e2e tests

* Added e2e tests for STYLE_* functions
2019-03-13 14:51:30 -04:00

62 lines
1.3 KiB
Go

package collections_test
import (
"context"
"testing"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/collections"
. "github.com/smartystreets/goconvey/convey"
)
func TestReverse(t *testing.T) {
Convey("When args are not passed", t, func() {
Convey("It should return an error", func() {
var err error
_, err = collections.Reverse(context.Background())
So(err, ShouldBeError)
})
})
Convey("Should reverse a text with right encoding", t, func() {
out, _ := collections.Reverse(
context.Background(),
values.NewString("The quick brown 狐 jumped over the lazy 犬"),
)
So(out, ShouldEqual, "犬 yzal eht revo depmuj 狐 nworb kciuq ehT")
})
Convey("Should return a copy of an array with reversed elements", t, func() {
arr := values.NewArrayWith(
values.NewInt(1),
values.NewInt(2),
values.NewInt(3),
values.NewInt(4),
values.NewInt(5),
values.NewInt(6),
)
out, err := collections.Reverse(
context.Background(),
arr,
)
So(err, ShouldBeNil)
So(out.String(), ShouldEqual, "[6,5,4,3,2,1]")
})
Convey("Should return an empty array when there no elements in a source one", t, func() {
arr := values.NewArray(0)
out, err := collections.Reverse(
context.Background(),
arr,
)
So(err, ShouldBeNil)
So(out.String(), ShouldEqual, "[]")
})
}