Package com.odiago.flumebase.lang

Examples of com.odiago.flumebase.lang.TypeChecker


  }

  @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.
View Full Code Here

TOP

Related Classes of com.odiago.flumebase.lang.TypeChecker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.