Skip to content

Commit 915435b

Browse files
committed
Test using custom set of operators
1 parent d5f93b8 commit 915435b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/test/groovy/cz/jirutka/rsql/parser/RSQLParserTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class RSQLParserTest extends Specification {
3737
def factory = new NodesFactory(defaultOperators())
3838

3939

40+
def 'throw exception when created with null or empty set of operators'() {
41+
when:
42+
new RSQLParser(operators as Set)
43+
then:
44+
thrown IllegalArgumentException
45+
where:
46+
operators << [null, []]
47+
}
48+
49+
4050
def 'throw exception when input is null'() {
4151
when:
4252
parse(null)
@@ -177,6 +187,23 @@ class RSQLParserTest extends Specification {
177187
}
178188

179189

190+
def 'use parser with custom set of operators'() {
191+
setup:
192+
def allOperator = new ComparisonOperator('=all=', true)
193+
def parser = new RSQLParser([EQUAL, allOperator] as Set)
194+
def expected = and(eq('name', 'TRON'), new ComparisonNode(allOperator, 'genres', ['sci-fi', 'thriller']))
195+
196+
expect:
197+
parser.parse('name==TRON;genres=all=(sci-fi,thriller)') == expected
198+
199+
when: 'unsupported operator used'
200+
parser.parse('name==TRON;year=ge=2010')
201+
then:
202+
def ex = thrown(RSQLParserException)
203+
ex.cause instanceof UnknownOperatorException
204+
}
205+
206+
180207
//////// Helpers ////////
181208

182209
def parse(String rsql) { new RSQLParser().parse(rsql) }

0 commit comments

Comments
 (0)