}
@Test
public void testOr() throws Exception {
Expr binExpr;
TypeChecker checker;
Object value;
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE),
BinOp.Or,
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE));
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.BOOLEAN), Boolean.FALSE),
BinOp.Or,
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE));
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.BOOLEAN), Boolean.TRUE),
BinOp.Or,
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
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.BOOLEAN), Boolean.FALSE),
BinOp.Or,
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
value = binExpr.eval(getEmptyEventWrapper());
assertEquals(Boolean.FALSE, value);
try {
// This should cause a typechecker exception.
binExpr = new BinExpr(
new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE),
BinOp.Or,
new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
checker = new TypeChecker(new HashSymbolTable());
binExpr.accept(checker);
fail("Expected typechecker error ; int does not promote to boolean.");
} catch (VisitException ve) {
// Expected.