TypeChecker checker;
Object value;
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(10)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Integer.valueOf(-10), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-42)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Integer.valueOf(42), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(0)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Integer.valueOf(0), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.BIGINT), Long.valueOf(-42)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Long.valueOf(42), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(-42f)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Float.valueOf(42f), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.DOUBLE), Double.valueOf(-42)));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Double.valueOf(42), value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getNullable(Type.TypeName.DOUBLE), null));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(null, value);
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(12))));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
value = unaryExpr.eval(getEmptyEventWrapper());
assertEquals(Integer.valueOf(12), value);
try {
unaryExpr = new UnaryExpr(UnaryOp.Minus,
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), "hello"));
checker = new TypeChecker(new HashSymbolTable());
unaryExpr.accept(checker);
fail("Expected typechecker error on -(STRING)");
} catch (TypeCheckException tce) {
// expected this -- ok.
}