ScoreVisitorImpl extends AbstractParseTreeVisitor<FixValue<?>> implements ScoreVisitor<FixValue<?>> { @Override public FixValue<?> visitAnyExpression(AnyExpressionContext ctx) { return visitChildren(ctx); } ScoreVisitorImpl(SymbolResolver symbolResolver);  ScoreVisitorImpl(SymbolResolver symbolResolver, SemanticErrorListener errorListener); boolean isTrace(); void setTrace(boolean trace); @Override FixValue<?> visitAddSub(AddSubContext ctx); @Override FixValue<?> visitAnyExpression(AnyExpressionContext ctx); @Override FixValue<?> visitAssignment(AssignmentContext ctx); @Override FixValue<?> visitCharacter(CharacterContext ctx); @Override FixValue<?> visitContains(ContainsContext ctx); @Override FixValue<?> visitDateonly(DateonlyContext ctx); @Override FixValue<?> visitDecimal(DecimalContext ctx); @Override FixValue<?> visitDuration(DurationContext ctx); @Override FixValue<Boolean> visitEquality(EqualityContext ctx); @Override FixValue<?> visitExist(ExistContext ctx); @Override FixValue<?> visitIndex(IndexContext ctx); @Override FixValue<?> visitInteger(IntegerContext ctx); @SuppressWarnings("unchecked") @Override FixValue<Boolean> visitLogicalAnd(LogicalAndContext ctx); @Override FixValue<Boolean> visitLogicalNot(LogicalNotContext ctx); @Override FixValue<Boolean> visitLogicalOr(LogicalOrContext ctx); @Override FixValue<?> visitMulDiv(MulDivContext ctx); @Override FixValue<?> visitParens(ParensContext ctx); @Override FixValue<?> visitPred(PredContext ctx); @Override FixValue<?> visitQual(QualContext ctx); @Override FixValue<?> visitRange(RangeContext ctx); @Override FixValue<Boolean> visitRelational(RelationalContext ctx); @Override FixValue<?> visitString(StringContext ctx); @Override FixValue<?> visitTimeonly(TimeonlyContext ctx); @Override FixValue<?> visitTimestamp(TimestampContext ctx); @SuppressWarnings("unchecked") @Override FixValue<?> visitUnaryMinus(UnaryMinusContext ctx); @Override FixValue<?> visitVar(VarContext ctx); @Override FixValue<?> visitVariable(VariableContext ctx);  }
@Test public void testVisitAnyExpression() throws IOException { TestData[] data = new TestData[] {new TestData("!(33 == 4 and 5 < 6) and 12 >= 11", Boolean.TRUE),}; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); FixValue<?> fixValue = (FixValue<?>) expression; assertEquals(data[i].getExpected(), fixValue.getValue()); } }
@Test public void testVisitMissingAssignment() throws IOException { TestData[] data = new TestData[] { new TestData("$x = $foo", 33), }; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); assertNull(expression); assertTrue(errorListener.hasError()); } }
@Test public void testReAssignment() throws IOException { TestData[] data = new TestData[] { new TestData("$x = 33", 33), new TestData("$x = 44", 44), }; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); FixValue<?> fixValue = (FixValue<?>) expression; assertEquals(data[i].getExpected(), fixValue.getValue()); assertEquals("x", fixValue.getName()); } }
@Test public void testVisitBooleanNot() throws IOException { TestData[] data = new TestData[] {new TestData("!(33 > 4)", Boolean.FALSE), new TestData("!(33 < 4)", Boolean.TRUE),}; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); FixValue<?> fixValue = (FixValue<?>) expression; assertEquals(data[i].getExpected(), fixValue.getValue()); } }
@Test public void testVisitMulDivError() throws IOException { TestData[] data = new TestData[] { new TestData("44 / 0", Integer.valueOf(2)), }; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); assertNull(expression); assertTrue(errorListener.hasError()); } }
@Test public void testVisitExistNotFound() throws IOException, ScoreException, ModelException { final String varName = "$orderCount"; final String dslExpression = "exists " + varName; ScoreParser parser = parse(dslExpression); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); assertTrue(expression instanceof FixValue<?>); @SuppressWarnings("unchecked") FixValue<Boolean> fixValue = (FixValue<Boolean>) expression; assertEquals(FixType.BooleanType, fixValue.getType()); assertFalse(fixValue.getValue()); }
@Test public void testVisitDate() throws IOException { final String value = "#2017-02-03#"; ScoreParser parser = parse(value); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); assertTrue(expression instanceof FixValue<?>); FixValue<?> fixValue = (FixValue<?>) expression; assertEquals(FixType.UTCDateOnly, fixValue.getType()); assertEquals(LocalDate.parse(value.substring(1, value.lastIndexOf('#'))), fixValue.getValue()); }