ExpressionParser { static Parser<Expression> compare(Parser<Expression> expr) { return Parsers.or( compare(expr, ">", Op.GT), compare(expr, ">=", Op.GE), compare(expr, "<", Op.LT), compare(expr, "<=", Op.LE), compare(expr, "=", Op.EQ), compare(expr, "<>", Op.NE), nullCheck(expr), like(expr), between(expr)); }    }
@Test public void testCompare() { Parser<Expression> parser = ExpressionParser.compare(NUMBER); TerminalParserTest.assertParser(parser, "1 = 1", new BinaryExpression(number(1), Op.EQ, number(1))); TerminalParserTest.assertParser(parser, "1 < 2", new BinaryExpression(number(1), Op.LT, number(2))); TerminalParserTest.assertParser(parser, "1 <= 2", new BinaryExpression(number(1), Op.LE, number(2))); TerminalParserTest.assertParser(parser, "1 <> 2", new BinaryExpression(number(1), Op.NE, number(2))); TerminalParserTest.assertParser(parser, "2 > 1", new BinaryExpression(number(2), Op.GT, number(1))); TerminalParserTest.assertParser(parser, "2 >= 1", new BinaryExpression(number(2), Op.GE, number(1))); TerminalParserTest.assertParser(parser, "1 is null", new BinaryExpression(number(1), Op.IS, NullExpression.instance)); TerminalParserTest.assertParser(parser, "1 is not null", new BinaryExpression(number(1), Op.NOT, NullExpression.instance)); TerminalParserTest.assertParser(parser, "1 like 2", new LikeExpression(number(1), true, number(2), null)); TerminalParserTest.assertParser(parser, "1 BETWEEN 0 and 2", new BetweenExpression(number(1), true, number(0), number(2))); TerminalParserTest.assertParser(parser, "1 not between 2 and 0", new BetweenExpression(number(1), false, number(2), number(0))); }