ExpressionParser { private Expression parseExpression() throws UriParserException, UriValidationException { Expression left = parseAnd(); while (tokenizer.next(TokenKind.OrOperator)) { checkType(left, EdmPrimitiveTypeKind.Boolean); checkNoCollection(left); final Expression right = parseAnd(); checkType(right, EdmPrimitiveTypeKind.Boolean); checkNoCollection(right); left = new BinaryImpl(left, BinaryOperatorKind.OR, right, odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean)); } return left; } ExpressionParser(final Edm edm, final OData odata); Expression parse(UriTokenizer tokenizer, final EdmType referringType,
      final Collection<String> crossjoinEntitySetNames, final Map<String, AliasQueryOption> aliases);  }
@Test public void equality() throws Exception { Expression expression = parseExpression("5 eq 5"); assertEquals("{5 EQ 5}", expression.toString()); expression = parseExpression("5 ne 5"); assertEquals("{5 NE 5}", expression.toString()); assertEquals("{1 EQ null}", parseExpression("1 eq null").toString()); assertEquals("{null NE 2}", parseExpression("null ne 2").toString()); assertEquals("{null EQ null}", parseExpression("null eq null").toString()); wrongExpression("5 eq '5'"); }
@Test public void testIntegerTypes() throws Exception { Expression expression = parseExpression("5 ne 545678979"); assertEquals("{5 NE 545678979}", expression.toString()); expression = parseExpression("5456 eq 5456"); assertEquals("{5456 EQ 5456}", expression.toString()); expression = parseExpression("null ne 54561234567"); assertEquals("{null NE 54561234567}", expression.toString()); expression = parseExpression("null ne 255"); assertEquals("{null NE 255}", expression.toString()); expression = parseExpression("123 le 2551234567890000999999"); assertEquals("{123 LE 2551234567890000999999}", expression.toString()); }
@Test public void relational() throws Exception { Expression expression = parseExpression("5 gt 5"); assertEquals("{5 GT 5}", expression.toString()); expression = parseExpression("5 ge 5"); assertEquals("{5 GE 5}", expression.toString()); expression = parseExpression("5 lt 5"); assertEquals("{5 LT 5}", expression.toString()); expression = parseExpression("5 le 5"); assertEquals("{5 LE 5}", expression.toString()); assertEquals("{5 LE 5.1}", parseExpression("5 le 5.1").toString()); assertEquals("{1 GT null}", parseExpression("1 gt null").toString()); assertEquals("{null GE 2}", parseExpression("null ge 2").toString()); assertEquals("{null LE null}", parseExpression("null le null").toString()); wrongExpression("5 gt duration'PT5H'"); }
@Test public void additive() throws Exception { Expression expression = parseExpression("5 add 5"); assertEquals("{5 ADD 5}", expression.toString()); expression = parseExpression("5 sub 5.1"); assertEquals("{5 SUB 5.1}", expression.toString()); expression = parseExpression("2000-02-29 sub 2016-02-29"); assertEquals("{2000-02-29 SUB 2016-02-29}", expression.toString()); expression = parseExpression("2000-02-29T00:00:00Z sub 2016-02-29T01:02:03Z"); assertEquals("{2000-02-29T00:00:00Z SUB 2016-02-29T01:02:03Z}", expression.toString()); expression = parseExpression("duration'PT1H' add duration'PT1M'"); assertEquals("{duration'PT1H' ADD duration'PT1M'}", expression.toString()); expression = parseExpression("2016-01-01 add duration'P60D'"); assertEquals("{2016-01-01 ADD duration'P60D'}", expression.toString()); expression = parseExpression("2000-02-29T00:00:00Z add duration'PT12H'"); assertEquals("{2000-02-29T00:00:00Z ADD duration'PT12H'}", expression.toString()); assertEquals("{1 ADD null}", parseExpression("1 add null").toString()); assertEquals("{null ADD 2}", parseExpression("null add 2").toString()); assertEquals("{null SUB null}", parseExpression("null sub null").toString()); wrongExpression("1 add '2'"); wrongExpression("'1' add 2"); wrongExpression("1 add 2000-02-29"); wrongExpression("11:12:13 sub 2000-02-29T11:12:13Z"); wrongExpression("2000-02-29 add 2016-02-29"); wrongExpression("2000-02-29T00:00:00Z add 2016-02-29T01:02:03Z"); wrongExpression("2000-02-29T00:00:00Z add 1"); wrongExpression("2000-02-29 sub 1"); wrongExpression("duration'P7D' add 2000-02-29"); }
@Test public void multiplicative() throws Exception { Expression expression = parseExpression("5 mul 5"); assertEquals("{5 MUL 5}", expression.toString()); expression = parseExpression("5 div 5"); assertEquals("{5 DIV 5}", expression.toString()); expression = parseExpression("5 mod 5"); assertEquals("{5 MOD 5}", expression.toString()); wrongExpression("1 mod '2'"); }
@Test public void unary() throws Exception { Expression expression = parseExpression("-5"); assertEquals("-5", expression.toString()); assertEquals("{MINUS -1}", parseExpression("--1").toString()); assertEquals("{MINUS duration'PT1M'}", parseExpression("-duration'PT1M'").toString()); expression = parseExpression("not false"); assertEquals("{NOT false}", expression.toString()); wrongExpression("not 11:12:13"); }
@Test public void grouping() throws Exception { Expression expression = parseExpression("-5 add 5"); assertEquals("{-5 ADD 5}", expression.toString()); expression = parseExpression("-(5 add 5)"); assertEquals("{MINUS {5 ADD 5}}", expression.toString()); expression = parseExpression("-( 5 add 5\t)"); assertEquals("{MINUS {5 ADD 5}}", expression.toString()); }
@Test public void precedence() throws Exception { assertEquals("{-1 ADD {2 DIV 3}}", parseExpression("-1 add 2 div 3").toString()); assertEquals("{true OR {{NOT false} AND true}}", parseExpression("true or not false and true").toString()); }