mirror of
https://github.com/MontFerret/ferret.git
synced 2025-06-27 00:41:09 +02:00
Bug/#142 clauses and statements (#148)
This commit is contained in:
@ -248,154 +248,6 @@ func TestFor(t *testing.T) {
|
||||
|
||||
So(string(out), ShouldEqual, `[1,2,3,4]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with LIMIT 2", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
p, err := c.Compile(`
|
||||
FOR i IN [ 1, 2, 3, 4, 1, 3 ]
|
||||
LIMIT 2
|
||||
RETURN i
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[1,2]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with LIMIT 2, 2", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
// 4 is offset
|
||||
// 2 is count
|
||||
p, err := c.Compile(`
|
||||
FOR i IN [ 1,2,3,4,5,6,7,8 ]
|
||||
LIMIT 4, 2
|
||||
RETURN i
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[5,6]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with SORT statement", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
p, 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
|
||||
SORT u.age
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"active":true,"age":29,"gender":"f"},{"active":true,"age":31,"gender":"m"},{"active":true,"age":36,"gender":"m"}]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with SORT DESC statement", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
p, 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
|
||||
SORT u.age DESC
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"active":true,"age":36,"gender":"m"},{"active":true,"age":31,"gender":"m"},{"active":true,"age":29,"gender":"f"}]`)
|
||||
})
|
||||
|
||||
Convey("Should compile query with SORT statement with multiple expressions", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
p, err := c.Compile(`
|
||||
LET users = [
|
||||
{
|
||||
active: true,
|
||||
age: 31,
|
||||
gender: "m"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 29,
|
||||
gender: "f"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 31,
|
||||
gender: "f"
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
age: 36,
|
||||
gender: "m"
|
||||
}
|
||||
]
|
||||
FOR u IN users
|
||||
SORT u.age, u.gender
|
||||
RETURN u
|
||||
`)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := p.Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `[{"active":true,"age":29,"gender":"f"},{"active":true,"age":31,"gender":"f"},{"active":true,"age":31,"gender":"m"},{"active":true,"age":36,"gender":"m"}]`)
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkForEmpty(b *testing.B) {
|
||||
|
Reference in New Issue
Block a user