Exemplo n.º 1
0
  @Test
  public void testTypeCheckingVisitorTypeDeclaration() throws IOException, ParseException {
    final String source =
        "type my_bool = bool;\ntype Coordinates = { x: float, y: float };\ntype CityMap = map [city_name: string] of Coordinates;\n";

    final SymbolTable st = new SymbolTable();

    SizzleParser.ReInit(new StringReader(source));
    TestTypeCheckingVisitor.typeChecker.visit(SizzleParser.Start(), st);

    Assert.assertEquals(
        "my_bool is not an alias for bool",
        new SizzleName(new SizzleBool()),
        st.getType("my_bool"));
    final ArrayList<SizzleType> members =
        new ArrayList<SizzleType>(Arrays.asList(new SizzleFloat(), new SizzleFloat()));
    Assert.assertEquals(
        "Coordinates is not is not an alias for a tuple of x: float, y: float",
        new SizzleName(new SizzleTuple(members)),
        st.getType("Coordinates"));
    Assert.assertEquals(
        "CityMap is not an alias for a mapping from string to tuple of x: float, y: float",
        new SizzleName(new SizzleMap(new SizzleString(), new SizzleName(new SizzleTuple(members)))),
        st.getType("CityMap"));
  }