1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/compiler/compiler_str_test.go
2019-09-01 21:41:16 -04:00

103 lines
1.8 KiB
Go

package compiler_test
import (
"context"
"encoding/json"
"fmt"
"github.com/MontFerret/ferret/pkg/compiler"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestString(t *testing.T) {
Convey("Should be possible to use multi line string", t, func() {
out := compiler.New().
MustCompile(`
RETURN "
FOO
BAR
"
`).
MustRun(context.Background())
So(string(out), ShouldEqual, `"\nFOO\nBAR\n"`)
})
Convey("Should be possible to use multi line string with nested strings using backtick", t, func() {
compiler.New().
MustCompile(fmt.Sprintf(`
RETURN %s<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GetTitle</title>
</head>
<body>
Hello world
</body>
</html>%s
`, "`", "`")).
MustRun(context.Background())
out, err := json.Marshal(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GetTitle</title>
</head>
<body>
Hello world
</body>
</html>`)
So(err, ShouldBeNil)
So(string(out), ShouldEqual, string(out))
})
Convey("Should be possible to use multi line string with nested strings using tick", t, func() {
compiler.New().
MustCompile(fmt.Sprintf(`
RETURN %s<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GetTitle</title>
</head>
<body>
Hello world
</body>
</html>%s
`, "´", "´")).
MustRun(context.Background())
out, err := json.Marshal(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GetTitle</title>
</head>
<body>
Hello world
</body>
</html>`)
So(err, ShouldBeNil)
So(string(out), ShouldEqual, string(out))
})
}
func BenchmarkStringLiteral(b *testing.B) {
p := compiler.New().MustCompile(`
RETURN "
FOO
BAR
"
`)
for n := 0; n < b.N; n++ {
p.Run(context.Background())
}
}