1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/compiler/compiler_func_ns_test.go
Tim Voronov 101da6323a
Added namespaces support (#296)
* Added namespaces support

* Updated regexp for func name validation
2019-05-10 12:53:31 -04:00

95 lines
1.8 KiB
Go

package compiler_test
import (
"context"
"github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestFunctionNSCall(t *testing.T) {
Convey("Should compile RETURN T::SPY", t, func() {
c := compiler.New()
var counter int
err := c.RegisterFunction("T::SPY", func(_ context.Context, _ ...core.Value) (core.Value, error) {
counter++
return values.None, nil
})
So(err, ShouldBeNil)
p, err := c.Compile(`
RETURN T::SPY()
`)
So(err, ShouldBeNil)
_, err = p.Run(context.Background())
So(err, ShouldBeNil)
So(counter, ShouldEqual, 1)
})
Convey("Should compile RETURN T::UTILS::SPY", t, func() {
c := compiler.New()
var counter int
err := c.RegisterFunction("T::UTILS::SPY", func(_ context.Context, _ ...core.Value) (core.Value, error) {
counter++
return values.None, nil
})
So(err, ShouldBeNil)
p, err := c.Compile(`
RETURN T::UTILS::SPY()
`)
So(err, ShouldBeNil)
_, err = p.Run(context.Background())
So(err, ShouldBeNil)
So(counter, ShouldEqual, 1)
})
Convey("Should NOT compile RETURN T:UTILS::SPY", t, func() {
c := compiler.New()
var counter int
err := c.RegisterFunction("T::UTILS::SPY", func(_ context.Context, _ ...core.Value) (core.Value, error) {
counter++
return values.None, nil
})
So(err, ShouldBeNil)
_, err = c.Compile(`
RETURN T:UTILS::SPY()
`)
So(err, ShouldNotBeNil)
})
Convey("Should NOT register RETURN T:UTILS::SPY", t, func() {
c := compiler.New()
var counter int
err := c.RegisterFunction("T::UTILS:SPY", func(_ context.Context, _ ...core.Value) (core.Value, error) {
counter++
return values.None, nil
})
So(err, ShouldNotBeNil)
})
}