mirror of
https://github.com/MontFerret/ferret.git
synced 2025-06-23 00:28:10 +02:00
@ -287,120 +287,6 @@ func TestFor(t *testing.T) {
|
||||
So(string(out), ShouldEqual, `[5,6]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with FILTER i > 2", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
FOR i IN [ 1, 2, 3, 4, 1, 3 ]
|
||||
FILTER i > 2
|
||||
RETURN i
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[3,4,3]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with FILTER i > 1 AND i < 3", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
FOR i IN [ 1, 2, 3, 4, 1, 3 ]
|
||||
FILTER i > 1 AND i < 4
|
||||
RETURN i
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[2,3,3]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with multiple FILTER statements", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
LET users = [
|
||||
{
|
||||
active: true,
|
||||
age: 31,
|
||||
gender: "m"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 29,
|
||||
gender: "f"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 36,
|
||||
gender: "m"
|
||||
}
|
||||
]
|
||||
FOR u IN users
|
||||
FILTER u.active == true
|
||||
FILTER u.age < 35
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"active":true,"age":31,"gender":"m"},{"active":true,"age":29,"gender":"f"}]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with multiple FILTER statements", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
prog, err := c.Compile(`
|
||||
LET users = [
|
||||
{
|
||||
active: true,
|
||||
age: 31,
|
||||
gender: "m"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 29,
|
||||
gender: "f"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 36,
|
||||
gender: "m"
|
||||
},
|
||||
{
|
||||
active: false,
|
||||
age: 69,
|
||||
gender: "m"
|
||||
}
|
||||
]
|
||||
FOR u IN users
|
||||
FILTER u.active == true
|
||||
LIMIT 2
|
||||
FILTER u.gender == "m"
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := prog.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"active":true,"age":31,"gender":"m"}]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with SORT statement", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
|
Reference in New Issue
Block a user