mirror of
https://github.com/MontFerret/ferret.git
synced 2026-05-22 10:15:21 +02:00
#2 Added IN operator
This commit is contained in:
@@ -1053,6 +1053,38 @@ func TestLogicalOperators(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `23`)
|
||||
})
|
||||
|
||||
Convey("NOT TRUE should return false", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
RETURN NOT TRUE
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `false`)
|
||||
})
|
||||
|
||||
Convey("NOT u.valid should return true", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
LET u = { valid: false }
|
||||
|
||||
RETURN NOT u.valid
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `true`)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMathOperators(t *testing.T) {
|
||||
@@ -1523,6 +1555,53 @@ func TestRangeOperator(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInOperator(t *testing.T) {
|
||||
Convey("1 IN [1,2,3] should return true", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
RETURN 1 IN [1,2,3]
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `true`)
|
||||
})
|
||||
|
||||
Convey("4 IN [1,2,3] should return false", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
RETURN 4 IN [1,2,3]
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `false`)
|
||||
})
|
||||
|
||||
Convey("4 NOT IN [1,2,3] should return true", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
RETURN 4 NOT IN [1,2,3]
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, `true`)
|
||||
})
|
||||
}
|
||||
|
||||
//func TestHtml(t *testing.T) {
|
||||
// Convey("Should load a document", t, func() {
|
||||
// c := compiler.New()
|
||||
|
||||
@@ -815,6 +815,45 @@ func (v *visitor) doVisitExpression(ctx *fql.ExpressionContext, scope *scope) (c
|
||||
)
|
||||
}
|
||||
|
||||
inOp := ctx.In()
|
||||
|
||||
if inOp != nil {
|
||||
exps, err := v.doVisitAllExpressions(ctx.AllExpression(), scope)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
left := exps[0]
|
||||
right := exps[1]
|
||||
|
||||
return operators.NewInOperator(
|
||||
v.getSourceMap(ctx),
|
||||
left,
|
||||
right,
|
||||
ctx.Not() != nil,
|
||||
)
|
||||
}
|
||||
|
||||
notOp := ctx.Not()
|
||||
|
||||
if notOp != nil {
|
||||
exps, err := v.doVisitAllExpressions(ctx.AllExpression(), scope)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
exp := exps[0]
|
||||
|
||||
return operators.NewLogicalOperator(
|
||||
v.getSourceMap(ctx),
|
||||
nil,
|
||||
exp,
|
||||
"NOT",
|
||||
)
|
||||
}
|
||||
|
||||
rangeOp := ctx.RangeOperator()
|
||||
|
||||
if rangeOp != nil {
|
||||
|
||||
Reference in New Issue
Block a user