public void testArithmetic() {
Parser<Expression> parser = ExpressionParser.arithmetic(NUMBER);
assertParser(parser, "1", number(1));
assertParser(parser, "((1))", number(1));
assertParser(parser, "1 + 2", new BinaryExpression(number(1), Op.PLUS, number(2)));
assertParser(parser, "2 * (1 + (2))",
new BinaryExpression(number(2), Op.MUL,
new BinaryExpression(number(1), Op.PLUS, number(2))));
assertParser(parser, "2 - 1 / (2)",
new BinaryExpression(number(2), Op.MINUS,
new BinaryExpression(number(1), Op.DIV, number(2))));
assertParser(parser, "2 * 1 % -2",
new BinaryExpression(
new BinaryExpression(number(2), Op.MUL, number(1)),
Op.MOD, new UnaryExpression(Op.NEG, number(2))));
assertParser(parser, "f(1)", FunctionExpression.of(QualifiedName.of("f"), number(1)));
assertParser(parser, "foo.bar(1, 2) + baz(foo.bar(1 / 2))",
new BinaryExpression(
FunctionExpression.of(QualifiedName.of("foo", "bar"), number(1), number(2)),
Op.PLUS,
FunctionExpression.of(QualifiedName.of("baz"),
FunctionExpression.of(QualifiedName.of("foo", "bar"), new BinaryExpression(
number(1), Op.DIV, number(2))))));
}