2019-03-13 20:51:30 +02:00
|
|
|
package collections_test
|
2018-10-06 03:27:34 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-03-13 20:51:30 +02:00
|
|
|
"testing"
|
|
|
|
|
2018-10-06 03:27:34 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
2019-03-13 20:51:30 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/stdlib/collections"
|
2018-10-06 03:27:34 +02:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReverse(t *testing.T) {
|
2019-03-13 20:51:30 +02:00
|
|
|
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")
|
|
|
|
})
|
|
|
|
|
2018-10-06 03:27:34 +02:00
|
|
|
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),
|
|
|
|
)
|
|
|
|
|
2019-03-13 20:51:30 +02:00
|
|
|
out, err := collections.Reverse(
|
2018-10-06 03:27:34 +02:00
|
|
|
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)
|
|
|
|
|
2019-03-13 20:51:30 +02:00
|
|
|
out, err := collections.Reverse(
|
2018-10-06 03:27:34 +02:00
|
|
|
context.Background(),
|
|
|
|
arr,
|
|
|
|
)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(out.String(), ShouldEqual, "[]")
|
|
|
|
})
|
|
|
|
}
|