1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/compiler/compiler_func_test.go
2018-10-15 18:50:55 -04:00

85 lines
1.4 KiB
Go

package compiler_test
import (
"context"
"github.com/MontFerret/ferret/pkg/compiler"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestFunctionCall(t *testing.T) {
Convey("Should compile RETURN TYPENAME(1)", t, func() {
c := compiler.New()
prog, err := c.Compile(`
RETURN TYPENAME(1)
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `"int"`)
})
Convey("Should compile WAIT(10) RETURN 1", t, func() {
c := compiler.New()
prog, err := c.Compile(`
WAIT(10)
RETURN 1
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `1`)
})
Convey("Should compile LET duration = 10 WAIT(duration) RETURN 1", t, func() {
c := compiler.New()
prog, err := c.Compile(`
LET duration = 10
WAIT(duration)
RETURN 1
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `1`)
})
Convey("Should compile function call inside FOR IN statement", t, func() {
c := compiler.New()
prog, err := c.Compile(`
FOR i IN [1, 2, 3, 4]
LET duration = 10
WAIT(duration)
RETURN i * 2
`)
So(err, ShouldBeNil)
out, err := prog.Run(context.Background())
So(err, ShouldBeNil)
So(string(out), ShouldEqual, `[2,4,6,8]`)
})
}