Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Feb 21, 2020
1 parent d613b97 commit d0c6f50
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
126 changes: 126 additions & 0 deletions v5/pkg/tsl/tsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,132 @@ var _ = Describe("Parser", func() {
}
}`,
),

Entry(
"Use of . and / as valid identifier",
"a.b.c.d.f/g.h not ilike 'my%'",
`{
"func": "$not",
"left": {
"func": "$ilike",
"left": {
"func": "$ident",
"left": "a.b.c.d.f/g.h"
},
"right": {
"func": "$string",
"left": "my%"
}
}
}`,
),

Entry(
"Use escaping with identifier",
"`a` > [b] and \"c\" is not null",
`{
"func": "$and",
"left": {
"func": "$gt",
"left": {
"func": "$ident",
"left": "a"
},
"right": {
"func": "$ident",
"left": "b"
}
},
"right": {
"func": "$exists",
"left": {
"func": "$ident",
"left": "c"
}
}
}`,
),

Entry(
"Use identifiers with math operators on right hand side",
"a > (b + 1)",
`{
"func": "$gt",
"left": {
"func": "$ident",
"left": "a"
},
"right": {
"func": "$add",
"left": {
"func": "$ident",
"left": "b"
},
"right": {
"func": "$number",
"left": 1
}
}
}`,
),

Entry(
"Use SI units",
"a > 1Ki and b < 2Mi and c = 3Gi or d != 4Ti",
`{
"func": "$or",
"left": {
"func": "$and",
"left": {
"func": "$and",
"left": {
"func": "$gt",
"left": {
"func": "$ident",
"left": "a"
},
"right": {
"func": "$number",
"left": 1024
}
},
"right": {
"func": "$lt",
"left": {
"func": "$ident",
"left": "b"
},
"right": {
"func": "$number",
"left": 2097152
}
}
},
"right": {
"func": "$eq",
"left": {
"func": "$ident",
"left": "c"
},
"right": {
"func": "$number",
"left": 3221225472
}
}
},
"right": {
"func": "$ne",
"left": {
"func": "$ident",
"left": "d"
},
"right": {
"func": "$number",
"left": 4398046511104
}
}
}`,
),
)
})

Expand Down
5 changes: 5 additions & 0 deletions v5/pkg/walkers/semantics/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ var _ = Describe("Walk", func() {
Entry("not like bad", "title not like '%bad%'", true),
Entry("not ilike GOOD", "title not ilike '%GOOD%'", false),
Entry("not ilike BAD", "title not ilike '%BAD%'", true),

// Two identififers
Entry("more pages", "spec.pages <= spec.rating", false),
Entry("add pages to number", "spec.pages = (spec.rating + 9)", true),
Entry("multiply pages with number", "spec.pages < (spec.rating * 3)", true),
)
})

0 comments on commit d0c6f50

Please sign in to comment.