sourceprintertest.java
来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· Java 代码 · 共 870 行 · 第 1/3 页
JAVA
870 行
public void testLand() throws Exception {
assertEquals("true && false", pretty("true && false"));
}
public void testLe() throws Exception {
assertEquals("if (60 <= 70) {}", pretty("if (60<=70) {}"));
}
public void testListConstructor() throws Exception {
assertEquals("[a, b]", pretty("[a,b]"));
}
public void testLiteralAny() throws Exception {
assertEquals("any x = 2", pretty("any x = 2"));
}
public void testLiteralAs() throws Exception {
assertEquals("import java.util.Date as MyDate", pretty("import java.util.Date as MyDate"));
// todo suspicious spacing in the following assertion
assertEquals("x = 12 as Long ", pretty("x = 12 as Long"));
}
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 testLiteralBoolean() throws Exception {
assertEquals("boolean b = true", pretty("boolean b =true"));
}
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}"));
assertEquals("for (i in 1..100) {break 2}", pretty("for (i in 1..100) {break 2}"));
//todo should the colon be postfixed to the label?
assertEquals("for (i in 1..100) {break label1:}", pretty("for (i in 1..100) {break label1:}"));
}
public void testLiteralByte() throws Exception {
assertEquals("byte b = 1", pretty("byte b=1"));
}
public void testLiteralCase() throws Exception {
assertEquals("switch (foo) {case 1:x = 3}", pretty("switch(foo){case 1:x=3}"));
}
public void testLiteralCatch() throws Exception {
assertEquals("try {} catch (Exception e) {}", pretty("try {} catch (Exception e) {}"));
assertEquals("try {} catch (Exception e1) {} catch (Exception2 e2) {}", pretty("try {} catch (Exception e1) {} catch (Exception2 e2) {}"));
}
public void testLiteralChar() throws Exception {
assertEquals("char c = \"a\"", pretty("char c = \"a\""));
}
public void testLiteralClass() throws Exception {
assertEquals("public class Foo {int bar}", pretty("public class Foo{int bar}"));
}
public void testLiteralContinue() throws Exception {
assertEquals("for (i in 1..100) {continue }", pretty("for (i in 1..100) {continue}"));
assertEquals("for (i in 1..100) {continue 2}", pretty("for (i in 1..100) {continue 2}"));
//todo should the colon be postfixed to the label?
assertEquals("for (i in 1..100) {continue label1:}", pretty("for (i in 1..100) {continue label1:}"));
assertEquals("[1, 2, 3].each {continue }", pretty("[1,2,3].each{continue}"));
}
public void testLiteralDef() throws Exception {
assertEquals("def x = 123", pretty("def x=123"));
assertEquals("def myMethod() {return 0}", pretty("def myMethod(){return 0}"));
// note: def not needed in parameter declarations, but it is valid
//todo: is it ok to strip out 'def' from parameter declarations?
assertEquals("def foo( bar) {}", pretty("def foo(def bar){}"));
}
public void testLiteralDefault() throws Exception {
assertEquals("switch (foo) {default:x = 2}", pretty("switch(foo){default:x=2}"));
assertEquals("public @interface Foo{int bar() default 123}", pretty("public @interface Foo{int bar() default 123}"));
}
public void testLiteralDouble() throws Exception {
assertEquals("double d = 1.0", pretty("double d = 1.0"));
}
public void testLiteralElse() throws Exception {
assertEquals("if (false) {a = 1} else {a = 2}", pretty("if (false) {a=1} else {a=2}"));
}
public void testLiteralEnum() throws Exception {
assertEquals("enum Season {WINTER, SPRING, SUMMER, AUTUMN}", pretty("enum Season{WINTER,SPRING,SUMMER,AUTUMN}"));
}
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 testLiteralFalse() throws Exception {
assertEquals("if (false) {}", pretty("if (false) {}"));
}
public void testLiteralFinally() throws Exception {
assertEquals("try {}finally {}", pretty("try {}finally {}"));
}
public void testLiteralFloat() throws Exception {
assertEquals("float x", pretty("float x"));
}
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 testLiteralIf() throws Exception {
assertEquals("if (a == b) return false", pretty("if (a==b) return false"));
assertEquals("if (a == b) {}", pretty("if (a==b) {}"));
}
public void testLiteralImplements() throws Exception {
assertEquals("class Foo implements Bar {}", pretty("class Foo implements Bar {}"));
//todo the following is legal Java, but pretty strange...?
assertEquals("enum EarthSeason implements Season {SPRING}", pretty("enum EarthSeason implements Season{SPRING}"));
}
public void testLiteralImport() throws Exception {
assertEquals("import foo.Bar", pretty("import foo.Bar"));
assertEquals("import mooky.*", pretty("import mooky.*"));
}
public void testLiteralIn() throws Exception {
assertEquals("for (i in 1..10) {}", pretty("for (i in 1..10) {}"));
assertEquals("if (i in myList) {}", pretty("if (i in myList) {}"));
}
public void testLiteralInstanceOf() throws Exception {
assertEquals("if (a instanceof String) {}", pretty("if (a instanceof String) {}"));
}
public void testLiteralInt() throws Exception {
assertEquals("int a", pretty("int a"));
}
public void testLiteralInterface() throws Exception {
assertEquals("interface Foo{}", pretty("interface Foo{}"));
}
public void testLiteralLong() throws Exception {
assertEquals("long a = 1", pretty("long a = 1"));
}
public void testLiteralNative() throws Exception {
assertEquals("public class R {public native void seek(long pos) }", pretty("public class R{public native void seek(long pos)}"));
assertEquals("native foo() ", pretty("native foo()"));
}
public void testLiteralNew() throws Exception {
assertEquals("new Foo()", pretty("new Foo()"));
assertEquals("def x = new int[5]", pretty("def x = new int[5]"));
}
public void testLiteralNull() throws Exception {
assertEquals("def foo = null", pretty("def foo=null"));
}
public void testLiteralPackage() throws Exception {
assertEquals("package foo.bar", pretty("package foo.bar"));
}
public void testLiteralPrivate() throws Exception{
assertEquals("private bar", pretty("private bar"));
}
public void testLiteralProtected() throws Exception{
assertEquals("protected mooky", pretty("protected mooky"));
}
public void testLiteralPublic() throws Exception{
assertEquals("public foo", pretty("public foo"));
}
public void testLiteralReturn() throws Exception {
assertEquals("def foo() {return false}", pretty("def foo() { return false }"));
assertEquals("void bar() {return }", pretty("void bar() {return}"));
}
public void testLiteralShort() throws Exception {
assertEquals("short a = 1", pretty("short a = 1"));
}
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 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 testLiteralSwitch() throws Exception {
assertEquals("switch (foo) {case bar:x = 2}", pretty("switch(foo){case bar:x=2}"));
}
public void testLiteralSynchronized() throws Exception {
assertEquals("synchronized foo() {}", pretty("synchronized foo(){}"));
assertEquals("synchronized (t) {doStuff(t)}", pretty("synchronized (t) {doStuff(t)}"));
}
public void testLiteralThis() throws Exception {
assertEquals("this",pretty("this"));
assertEquals("this 2",pretty("this 2"));
assertEquals("this()",pretty("this()"));
assertEquals("this(1, 2, 3)",pretty("this(1,2,3)"));
assertEquals("this.x = this.y", pretty("this.x=this.y"));
}
public void testLiteralThreadsafe() throws Exception {
assertEquals("threadsafe foo() {}", pretty("threadsafe foo() {}"));
}
public void testLiteralThrow() throws Exception {
assertEquals("def foo() {if (false) throw new RuntimeException()}", pretty("def foo() {if (false) throw new RuntimeException()}"));
}
public void testLiteralThrows() throws Exception {
//todo AntlrParserPlugin: Unexpected node type: '.' found when expecting type: an identifier
assertEquals("def foo() throws java.io.IOException{}", pretty("def foo() throws java.io.IOException{}"));
}
public void testLiteralTransient() throws Exception {
assertEquals("transient bar", pretty("transient bar"));
}
public void testLiteralTrue() throws Exception {
assertEquals("foo = true", pretty("foo = true"));
}
public void testLiteralTry() throws Exception {
assertEquals("try {} catch (Exception e) {}", pretty("try {} catch (Exception e) {}"));
}
public void testLiteralVoid() throws Exception {
assertEquals("void foo() {}", pretty("void foo(){}"));
}
public void testLiteralVolatile() throws Exception {
assertEquals("volatile mooky", pretty("volatile mooky"));
}
public void testLiteralWhile() throws Exception {
assertEquals("while (true) {}", pretty("while(true){}"));
}
public void testLiteralWith() throws Exception {
assertEquals("with (myObject) {x = 1}", pretty("with(myObject) {x = 1}"));
}
public void testLnot() throws Exception {
assertEquals("if (!isRaining) {}", pretty("if (!isRaining) {}"));
}
public void testLor() throws Exception {
assertEquals("true || false", pretty("true || false"));
}
public void testLparen_FAILS() throws Exception { if (notYetImplemented()) return;
assertEquals("for (i in (history.size() - 1)..0) {}", pretty("for (i in (history.size() - 1)..0) {}"));
}
public void testLt() throws Exception {
assertEquals("if (3.4f < 12f) {}", pretty("if (3.4f < 12f) {}"));
}
public void testMapConstructor() throws Exception{
assertEquals("Map foo = [:]", pretty("Map foo = [:]"));
assertEquals("[a:1, b:2]", pretty("[a:1,b:2]"));
}
public void testMemberPointer() throws Exception {
assertEquals("def x = foo.&bar()", pretty("def x=foo.&bar()"));
}
public void testMethodCall() throws Exception {
assertEquals("foo(bar)", pretty("foo(bar)"));
assertEquals("[1, 2, 3].each {println it}", pretty("[1,2,3].each{println it}"));
assertEquals("foo(bar){mooky()}", pretty("foo(bar){mooky()}"));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?