1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-27 00:41:09 +02:00

Added possibility to use string literals as object poperties

This commit is contained in:
Tim Voronov
2018-10-22 15:11:00 -04:00
parent c706f01205
commit 685c5872aa
5 changed files with 398 additions and 314 deletions

View File

@ -2,6 +2,7 @@ package compiler_test
import (
"context"
"fmt"
"github.com/MontFerret/ferret/pkg/compiler"
. "github.com/smartystreets/goconvey/convey"
"testing"
@ -64,6 +65,42 @@ func TestMember(t *testing.T) {
So(string(out), ShouldEqual, `"wsx"`)
})
Convey("Object by literal with property defined as a string", func() {
c := compiler.New()
prog, err := c.Compile(`
LET obj = { "foo": "bar", "qaz": "wsx"}
RETURN obj["qaz"]
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `"wsx"`)
})
Convey("Object by literal with property defined as a multi line string", func() {
c := compiler.New()
prog, err := c.Compile(fmt.Sprintf(`
LET obj = { "foo": "bar", %s: "wsx"}
RETURN obj["qaz"]
`, "`qaz`"))
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `"wsx"`)
})
Convey("Object by variable", func() {
c := compiler.New()