mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-03 15:02:32 +02:00
* add one more test case * test nested namespace collision
This commit is contained in:
parent
7b2ed4c662
commit
9be14417b3
@ -106,22 +106,48 @@ func TestUseExpression(t *testing.T) {
|
||||
|
||||
So(string(out), ShouldEqual, "true")
|
||||
})
|
||||
|
||||
Convey("Nested namespace", func() {
|
||||
c := newCompiler()
|
||||
|
||||
c.Namespace("X").
|
||||
Namespace("Y").
|
||||
RegisterFunction("YYY_CONTAINS", strings.Contains)
|
||||
|
||||
Convey("Short path", func() {
|
||||
p, err := c.Compile(`
|
||||
USE X
|
||||
|
||||
RETURN Y::YYY_CONTAINS("s", "s")
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
out := p.MustRun(context.Background())
|
||||
|
||||
So(string(out), ShouldEqual, "true")
|
||||
})
|
||||
|
||||
Convey("Full path", func() {
|
||||
p, err := c.Compile(`
|
||||
USE X
|
||||
|
||||
RETURN X::Y::YYY_CONTAINS("s", "s")
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
out := p.MustRun(context.Background())
|
||||
|
||||
So(string(out), ShouldEqual, "true")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Should not compile", func() {
|
||||
|
||||
c := newCompiler()
|
||||
|
||||
c.Namespace("Z").
|
||||
RegisterFunction("XXX_TO_STRING", types.ToString)
|
||||
|
||||
// Y contain the same function as Z to test for future collistions
|
||||
c.Namespace("Y").
|
||||
RegisterFunction("XXX_TO_STRING", types.ToString)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Query string
|
||||
Name string
|
||||
Query string
|
||||
Compiler func() *compiler.Compiler
|
||||
}{
|
||||
{
|
||||
Name: "Wrong namespace format",
|
||||
@ -137,15 +163,6 @@ func TestUseExpression(t *testing.T) {
|
||||
|
||||
RETURN 1`,
|
||||
},
|
||||
{
|
||||
Name: "Functions collision",
|
||||
Query: `
|
||||
// Z and Y both contain function "XXX_CONTAINS"
|
||||
USE Z
|
||||
USE Y
|
||||
|
||||
RETURN 1`,
|
||||
},
|
||||
{
|
||||
Name: "USE namespace twice",
|
||||
Query: `
|
||||
@ -155,10 +172,58 @@ func TestUseExpression(t *testing.T) {
|
||||
RETURN XXX_CONTAINS("s", "s")
|
||||
`,
|
||||
},
|
||||
{
|
||||
Name: "Functions collision",
|
||||
Query: `
|
||||
// Z and Y both contain function "XXX_CONTAINS"
|
||||
USE Z
|
||||
USE Y
|
||||
|
||||
RETURN 1`,
|
||||
Compiler: func() *compiler.Compiler {
|
||||
c := newCompiler()
|
||||
|
||||
c.Namespace("Z").
|
||||
RegisterFunction("XXX_TO_STRING", types.ToString)
|
||||
|
||||
// Y contain the same function as Z to test for future collistions
|
||||
c.Namespace("Y").
|
||||
RegisterFunction("XXX_TO_STRING", types.ToString)
|
||||
|
||||
return c
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Nested namespace collision",
|
||||
Query: `
|
||||
USE X
|
||||
USE Z
|
||||
|
||||
RETURN 1
|
||||
`,
|
||||
Compiler: func() *compiler.Compiler {
|
||||
c := newCompiler()
|
||||
|
||||
c.Namespace("X").
|
||||
Namespace("Y").
|
||||
RegisterFunction("YYY_CONTAINS", strings.Contains)
|
||||
|
||||
c.Namespace("Z").
|
||||
Namespace("Y").
|
||||
RegisterFunction("YYY_CONTAINS", strings.Contains)
|
||||
|
||||
return c
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tC := range testCases {
|
||||
Convey(tC.Name, func() {
|
||||
c := newCompiler()
|
||||
if tC.Compiler != nil {
|
||||
c = tC.Compiler()
|
||||
}
|
||||
|
||||
_, err := c.Compile(tC.Query)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user