}
@Test
public void testEq() throws Exception {
Expr binExpr;
TypeChecker checker;
Object value;
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.FALSE, value);
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.TRUE, value);
binExpr = new BinExpr(
new ConstExpr(Type.getNullable(Type.TypeName.INT), null),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertNull(value);
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.TRUE, value);
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("ABC")));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.FALSE, value);
// integer-to-string promotion holds for the '=' operator too.
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("4")),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.TRUE, value);
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
BinOp.Eq,
new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("4")));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.TRUE, value);
}