예제 #1
0
  private static void helpTestExpr(String input, String expect, boolean simplify) throws Exception {
    Parser p = new Parser(new Scanner(null, new StringReader(input)));
    Atom expr = p.parseExpression();
    if (simplify) {
      expr = UnparseTests.stripUnnecessaryParenExprs(expr);
    }

    StringWriter sw = new StringWriter();
    UnparseVisitor uv = new UnparseVisitor(sw);
    expr.accept(uv);
    uv.close();
    String s = sw.toString();
    s = UnparseTests.replace(s, "((( ", "(");
    s = UnparseTests.replace(s, " )))", ")");
    Assert.assertEquals(expect, s);
  }
예제 #2
0
  @Test
  public void testLiterals() throws Exception {
    Object[][] tests =
        new Object[][] {
          {new FloatingPointLiteral(null, "-0.0D"), "-0.0D"},
          {new FloatingPointLiteral(null, "-0.0F"), "-0.0F"},
        };
    for (Object[] test : tests) {
      final Atom expr = (Atom) test[0];
      final String expected = (String) test[1];

      StringWriter sw = new StringWriter();
      UnparseVisitor uv = new UnparseVisitor(sw);
      expr.accept(uv);
      uv.close();
      Assert.assertEquals(expected, sw.toString());
    }
  }
예제 #3
0
 private void testInterfaceHelper(boolean interfaceMod) throws CompileException {
   Java.Modifiers maas = new Java.Modifiers(Mod.PUBLIC);
   if (interfaceMod) maas = maas.add(Mod.INTERFACE);
   Java.PackageMemberInterfaceDeclaration decl =
       new Java.PackageMemberInterfaceDeclaration(
           null,
           "foo",
           maas,
           "Foo",
           null, // optionalTypeParameters
           new Type[0] // extendedTypes
           );
   StringWriter sw = new StringWriter();
   UnparseVisitor uv = new UnparseVisitor(sw);
   decl.accept(uv);
   uv.close();
   String s = sw.toString();
   String correctString = "/**foo */ public interface Foo { }";
   Assert.assertEquals(correctString, UnparseTests.normalizeWhitespace(s));
 }