public void testElist() throws Exception { assertEquals("println 2 + 2", pretty("println 2 + 2")); assertEquals("for (i = 0; j = 2; i < 10; i++; j--){print i}", pretty("for (i = 0;j = 2;i < 10; i++; j--) {print i}")); // fails after parser assertEquals("foo()", pretty("foo()")); // empty ELIST assertEquals("foo(bar, mooky)", pretty("foo( bar , mooky )")); }
public void testExtendsClause() throws Exception { assertEquals("class Foo extends Bar {}", pretty("class Foo extends Bar {}")); assertEquals("interface Wibble extends Mooky{}", pretty("interface Wibble extends Mooky {}")); //todo spacing is odd, c.f. last space in class vs interface above }
public void testLiteralAs() throws Exception { // not in java assertEquals("import java.util.Date as MyDate", pretty("import java.util.Date as MyDate")); // not in java // todo suspicious spacing in the following assertion assertEquals("x = 12 as Long", pretty("x = 12 as Long")); // not in java }
public void testLiteralBreak() throws Exception { assertEquals("for (i in 1..100) {break }", pretty("for (i in 1..100) {break}")); assertEquals("switch (foo) {default:break }", pretty("switch(foo){default:break}")); assertEquals("def myMethod() {break }", pretty("def myMethod(){break}")); // fails after parser // deprecated -> assertEquals("for (i in 1..100) {break 2}", pretty("for (i in 1..100) {break 2}")); // fails after parser //todo should the colon be postfixed to the label? // deprecated -> assertEquals("for (i in 1..100) {break label1:}", pretty("for (i in 1..100) {break label1:}")); // fails after parser assertEquals("for (i in 1..100) {break label1}", pretty("for (i in 1..100) {break label1}")); }
public void testQuestion() throws Exception { assertEquals("foo == bar?10:20", pretty("foo==bar?10:20")); assertEquals("public boolean process(Set<? extends B> a) {println a}", pretty("public boolean process(Set<? extends B> a) {println a}")); assertEquals("public boolean process(Set<? extends B, ? super C> a) {println a}", pretty("public boolean process(Set<? extends B, ? super C> a) {println a}")); }
public void testSuperCtorCall() throws Exception { assertEquals("class Foo {Foo(int x) {super(12, 3)}}", pretty("class Foo{Foo(int x) {super(12, 3)}}")); assertEquals("class Foo {Foo(x) {super()}}", pretty("class Foo{Foo(x) {super()}}")); // todo: above is not quite the spacing I would expect, but good enough for now... // todo not yet implemented in parser: assertEquals("(new Outer()).super()", pretty("(new Outer()).super()")); }
public void testClosedBlock() throws Exception { // not in java assertEquals("[1, 2, 3].each {println it}", pretty("[1,2,3].each{println it}")); // not in java assertEquals("def x = foo.bar(mooky){x,y -> wibble(y, x)}", pretty("def x = foo.bar(mooky) {x,y-> wibble(y,x)}")); // not in java // todo: above is not quite the spacing I would expect, but good enough for now... }
public void testClosureList() throws Exception { // not in java assertEquals("for (int i = 0; i++; i < 10){}", pretty("for (int i=0;i++;i<10){}")); // not in java assertEquals("def x = (int i = 0; i++; i < 10)", pretty("def x = (int i=0;i++;i<10)")); // not in java //todo assertEquals("myMethod(int i = 0; i++; i < 10)", pretty("myMethod(int i=0;i++;i<10)")); // not in java }
public void testIdent() throws Exception { // used _everywhere_ , lets assume that the other specific // testcases include enough ident usage for now. assertEquals("foo.bar", pretty("foo.bar")); }
public void testLiteralAssert() throws Exception { assertEquals("assert a == true", pretty("assert a== true")); assertEquals("assert b == true : 99", pretty("assert b==true:99")); // todo is ',' deprecated now? //assertEquals("assert b == true , 99", pretty("assert b==true,99")); }
public void testLiteralSuper() throws Exception { assertEquals("class Foo {public Foo() {super()}}", pretty("class Foo{public Foo(){super()}}")); // todo will 'super' be allowed in non-parentheses method call styles? assertEquals("class Bar {public Bar() {super 99}}", pretty("class Bar{public Bar(){super 99}}")); assertEquals("class Bar {public Bar() {super(1, 2, 3)}}", pretty("class Bar{public Bar(){super(1,2,3)}}")); assertEquals("println(super.toString())", pretty("println(super.toString())")); //todo: doesn't parse correctly... assertEquals("class Foo<T super C> {T t}",pretty("class Foo<T super C> {T t}")); }
public void testParameterDef() throws Exception { assertEquals("def foo(bar) {}", pretty("def foo(bar){}")); assertEquals("def foo(String bar, String mooky) {}", pretty("def foo(String bar, String mooky){}")); assertEquals("def c = {x -> println x}", pretty("def c = {x->println x}")); assertEquals("def c = {x,y -> println(x + y)}", pretty("def c={x,y->println(x+y)}")); assertEquals("def c = {int x,int y -> println(x + y)}", pretty("def c={int x, int y->println(x+y)}")); }
public void testSlist() throws Exception { assertEquals("class Foo {private Foo() {println bar}}", pretty("class Foo {private Foo() {println bar}}")); assertEquals("if (true) {foo}", pretty("if (true) {foo}")); assertEquals("def x = foo.{bar}", pretty("def x = foo.{bar}")); // todo - inline open block is great, but it doesn't work as one would expect (yet). (c.f. with) assertEquals("def foo() {l:{x = 2}}", pretty("def foo(){l:{x=2}}")); // slist inside a method body (needed label to distinguish from a closure) assertEquals("switch (f) {case 1:break }", pretty("switch(f){case 1:break}")); // slist inside each case body... }
public void testLiteralExtends() throws Exception { assertEquals("class Foo extends java.util.Date {}", pretty("class Foo extends java.util.Date {}")); assertEquals("class Foo extends Bar {}", pretty("class Foo extends Bar {}")); assertEquals("interface Wibble extends Mooky{}", pretty("interface Wibble extends Mooky {}")); //todo spacing is odd, c.f. last space in class vs interface above assertEquals("public boolean process(Set<? extends TypeElement> annotations) {println annotations}", pretty("public boolean process(Set<? extends TypeElement> annotations) {println annotations}")); }
public void testLiteralStatic() throws Exception { assertEquals("static void foo() {}", pretty("static void foo() {}")); //classes, interfaces, class/instance vars and methods assertEquals("static int bar = 1", pretty("static int bar = 1")); //todo: this should parse... assertEquals("private static <T> void foo(List<T> list){}", pretty("private static <T> void foo(List<T> list){}")); assertEquals("class Foo {static {bar = 1}}", pretty("class Foo{static {bar=1}}")); }
public void testType() throws Exception { assertEquals("def bar", pretty("def bar")); assertEquals("public bar", pretty("public bar")); assertEquals("public String bar", pretty("public String bar")); assertEquals("String bar", pretty("String bar")); }
public void testLiteralFor() throws Exception { assertEquals("for (i in [1, 2, 3]) {}", pretty("for (i in [1,2,3]) {}")); // check non-braced single statement assertEquals("for (i in 1..100) rotateAntiClockwise()", pretty("for (i in 1..100) rotateAntiClockwise()")); }
public void testExpr_FAILS() throws Exception { if (notYetImplemented()) return; assertEquals("System.out.println(x)", pretty("System.out.println(x)")); assertEquals("return f", pretty("return f")); assertEquals("foo(bar);mooky(bar)", pretty("foo(bar);mooky(bar)")); }
public void testRegexpLiteral_FAILS() throws Exception { if (notYetImplemented()) return; // not in java //todo: these fail because regexp_literals are converted into string_literals on the antlr AST assertEquals("def x = /./", pretty("def x = /./")); // not in java assertEquals("def z = /blah\\s/", pretty("def z = /blah\\s/")); // actually: def z = /blah\s/ // not in java }
public void testEsc_FAILS() throws Exception { if (notYetImplemented()) return; // dquote-tab-dquote assertEquals("println \"\\\"\t\\\"\"", pretty("println \"\\\"\t\\\"\"")); }