@@ -0,0 +1,1132 @@
+package expr1;%0A%0Aimport static org.testng.Assert.assertEquals;%0A%0Aimport org.antlr.v4.runtime.tree.ParseTree;%0Aimport org.testng.annotations.Test;%0A%0Apublic class Expr1Test %7B%0A%0A%09@Test%0A%09public void integerLiteralStaysInteger() %7B%0A%09%09assertEquals(expr(%225%22), 5);%0A%09%7D%0A%0A%09@Test%0A%09public void plusAddsNumbers() %7B%0A%09%09assertEquals(expr(%225+4%22), 9);%0A%09%7D%0A%0A%09@Test%0A%09public void minusCanProduceNegativeNumber() %7B%0A%09%09assertEquals(expr(%225-8%22), -3);%0A%09%7D%0A%0A%09@Test%0A%09public void whitespacesAreIgnored() %7B%0A%09%09assertEquals(expr(%225%5Cn- 8%5Ct + 3%22), 0);%0A%09%7D%0A%0A%09@Test%0A%09public void multiplyPrecedesPlus() %7B%0A%09%09assertEquals(expr(%222+3*3%22), 11);%0A%09%09assertEquals(expr(%222*3+3%22), 9);%0A%09%7D%0A%0A%09@Test%0A%09public void parenthesisChangePrecedence() %7B%0A%09%09assertEquals(expr(%22(2+3)*3%22), 15);%0A%09%09assertEquals(expr(%222*(3+3)%22), 12);%0A%09%7D%0A%0A%09@Test(expectedExceptions = ExpressionException.class,%0A%09%09expectedExceptionsMessageRegExp = %22no viable alternative at input '-'%22)%0A%09public void cannotEnterNegativeNumber() %7B%0A%09%09expr(%22-1%22);%0A%09%7D%0A%0A%09private Object expr(String expression) %7B%0A%09%09ParseTree parseTree = ExpressionUtils.createParseTree(expression);%0A%09%09return new ExpressionCalculatorVisitor()%0A%09%09%09.visit(parseTree);%0A%09%7D%0A%7D%0A

test for simple grammar