1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-13 01:20:35 +02:00

RIGHT() function should return substr counting from right rather than… (#164)

This commit is contained in:
kiinoo
2018-11-07 23:04:18 +08:00
committed by Tim Voronov
parent 409a517e87
commit 528b60df24
2 changed files with 7 additions and 6 deletions

View File

@ -105,5 +105,5 @@ func Right(_ context.Context, args ...core.Value) (core.Value, error) {
return values.NewString(string(text)), nil return values.NewString(string(text)), nil
} }
return values.NewStringFromRunes(runes[pos:size]), nil return values.NewStringFromRunes(runes[size-pos : size]), nil
} }

View File

@ -2,10 +2,11 @@ package strings_test
import ( import (
"context" "context"
"testing"
"github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/strings" "github.com/MontFerret/ferret/pkg/stdlib/strings"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"testing"
) )
func TestSubstring(t *testing.T) { func TestSubstring(t *testing.T) {
@ -72,10 +73,10 @@ func TestLeft(t *testing.T) {
}) })
}) })
Convey("Left('foobar', 3) should return 'foo'", t, func() { Convey("Left('foobarfoobar', 3) should return 'foo'", t, func() {
out, _ := strings.Left( out, _ := strings.Left(
context.Background(), context.Background(),
values.NewString("foobar"), values.NewString("foobarfoobar"),
values.NewInt(3), values.NewInt(3),
) )
@ -107,10 +108,10 @@ func TestRight(t *testing.T) {
}) })
}) })
Convey("Right('foobar', 3) should return 'bar'", t, func() { Convey("Right('foobarfoobar', 3) should return 'bar'", t, func() {
out, _ := strings.Right( out, _ := strings.Right(
context.Background(), context.Background(),
values.NewString("foobar"), values.NewString("foobarfoobar"),
values.NewInt(3), values.NewInt(3),
) )