Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/stdlib/strings/substr.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ func Right(_ context.Context, args ...core.Value) (core.Value, error) {
return values.NewString(string(text)), nil
}

return values.NewStringFromRunes(runes[pos:size]), nil
return values.NewStringFromRunes(runes[size-pos : size]), nil
}
11 changes: 6 additions & 5 deletions pkg/stdlib/strings/substr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package strings_test

import (
"context"
"testing"

"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/strings"
. "github.com/smartystreets/goconvey/convey"
"testing"
)

func TestSubstring(t *testing.T) {
Expand Down Expand Up @@ -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(
context.Background(),
values.NewString("foobar"),
values.NewString("foobarfoobar"),
values.NewInt(3),
)

Expand Down Expand Up @@ -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(
context.Background(),
values.NewString("foobar"),
values.NewString("foobarfoobar"),
values.NewInt(3),
)

Expand Down