Skip to content

Commit

Permalink
Addedd extra unit tests and bench
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Dec 3, 2024
1 parent ec53d48 commit 1698f47
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pkg/compiler/compiler_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,28 @@ func BenchmarkForTernary(b *testing.B) {
RETURN foo ? TRUE : (FOR i IN 1..5 RETURN i*2)
`)
}

func BenchmarkForSort(b *testing.B) {
RunBenchmark(b, `
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
`)
}
69 changes: 68 additions & 1 deletion pkg/compiler/compiler_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,5 +1362,72 @@ LET users = [
map[string]any{"active": true, "age": 31, "gender": "m"},
map[string]any{"active": true, "age": 29, "gender": "f"},
}, "Should compile query with DESC SORT statement"),
})
CaseArray(` 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`,
[]any{
map[string]any{"active": true, "age": 29, "gender": "f"},
map[string]any{"active": true, "age": 31, "gender": "f"},
map[string]any{"active": true, "age": 31, "gender": "m"},
map[string]any{"active": true, "age": 36, "gender": "m"},
}, "Should compile query with SORT statement with multiple expressions"),
CaseArray(`
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
LET x = "foo"
TEST(x)
SORT u.age, u.gender
RETURN u
`, []any{
map[string]any{"active": true, "age": 29, "gender": "f"},
map[string]any{"active": true, "age": 31, "gender": "f"},
map[string]any{"active": true, "age": 31, "gender": "m"},
map[string]any{"active": true, "age": 36, "gender": "m"},
}, "Should define variables and call functions"),
}, runtime.WithFunction("TEST", func(ctx context.Context, args ...core.Value) (core.Value, error) {
return values.None, nil
}))
}

0 comments on commit 1698f47

Please sign in to comment.