/test/org/d/model/FormatterTest.java
Java | 672 lines | 622 code | 34 blank | 16 comment | 17 complexity | 55a2459eb3df821fd38ccffc2faddbde MD5 | raw file
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package org.d.model;
- import org.netbeans.modules.cnd.antlr.collections.AST;
- import java.io.StringReader;
- import java.text.MessageFormat;
- import junit.framework.TestCase;
- import org.d.generated.D2Lexer;
- import org.d.generated.D2Parser;
- import org.d.generated.DLexer;
- import org.d.generated.DParser;
- /**
- *
- * @author ellery
- */
- public class FormatterTest extends TestCase {
- public static DParser parser(String s) {
- DLexer lexer = new DLexer(new StringReader(s));
- DParser parser = new DParser(lexer);
- parser.initWithLines();
- return parser;
- }
- public static D2Parser parser2(String s) {
- D2Lexer lexer = new D2Lexer(new StringReader(s));
- D2Parser parser = new D2Parser(lexer);
- parser.initWithLines();
- return parser;
- }
- public static AST module(String s) {
- DParser parser = parser(s);
- parser.module();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST module2(String s) {
- D2Parser parser = parser2(s);
- parser.module();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST expression(String s) {
- DParser parser = parser(s);
- parser.exp();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST expression2(String s) {
- D2Parser parser = parser2(s);
- parser.exp();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST statement(String s) {
- DParser parser = parser(s);
- parser.statement();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST statement2(String s) {
- D2Parser parser = parser2(s);
- parser.statement();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST declDef(String s) {
- DParser parser = parser(s);
- parser.declDef();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public static AST declDef2(String s) {
- D2Parser parser = parser2(s);
- parser.declDef();
- if (parser.errors.isEmpty()) {
- return parser.getAST();
- }
- return null;
- }
- public FormatterTest(String testName) {
- super(testName);
- }
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
- /**
- * Test of format method, of class Formatter.
- */
- public void testFormat() {
- System.out.println("format");
- String[][] expressions = {
- {"a+b*c-d(e,f)^j;", "a + b * c - d(e, f) ^ j"},
- {"- a;", "-a"},
- {"a & - a;", "a & -a"},
- {"(a,b,c);", "(a, b, c)"},
- {"delete a;", "delete a"},
- {"cast( int )1.0;", "cast(int) 1.0"},
- {"int . max ;", "int.max"},
- {"new(1,2) int[][](1,2);", "new(1, 2) int[][](1, 2)"},
- {"a is null;", "a is null"},
- {"a !is null;", "a !is null"},
- {"a in null;", "a in null"},
- {"is(int);", "is(int)"},
- {"is(int i:j);", "is(int i: j)"},
- {"is( int[ ] i == j);", "is(int[] i == j)"},
- {"is( int == return);", "is(int == return)"},
- {"is( int == class);", "is(int == class)"},
- {"is( int == interface);", "is(int == interface)"},
- {"is( int == super);", "is(int == super)"},
- {"is( int == struct);", "is(int == struct)"},
- {"is( int == union);", "is(int == union)"},
- {"is( i == function);", "is(i == function)"},
- {"is( i == delegate);", "is(i == delegate)"},
- {"is( i == enum);", "is(i == enum)"},
- {"typeid(int);", "typeid(int)"},
- {"typeof(int.max);", "typeof(int.max)"},
- {"import(\"waga\");", "import(\"waga\")"},
- {"i!(i,j,k);", "i!(i, j, k)"},
- {"[1,2,3];", "[1, 2, 3]"},
- {"[1:\"a\",2:\"b\",3:\"c\"];", "[1: \"a\", 2: \"b\", 3: \"c\"]"},
- {"{ return 1; };", "{return 1;}"},
- {"delegate { return 1; };", "delegate {return 1;}"},
- {"delegate { };", "delegate {}"},
- {"delegate int{ return 1; };", "delegate int{return 1;}"},
- {"delegate int(int j){ return 1; };", "delegate int(int j){return 1;}"},
- {"(int j){ return 1; };", "(int j){return 1;}"},
- {"assert(false, \"hi!\");", "assert(false, \"hi!\")"},
- {"assert(true );", "assert(true)"},
- {"a[i ..j];", "a[i .. j]"},
- {"a[i ];", "a[i]"},
- {"a[i , j , k];", "a[i, j, k]"},
- {"a?b:c;", "a ? b : c"},
- {"&a;", "&a"},
- {"b&a;", "b & a"},
- {"+a;", "+a"},
- {"b+a;", "b + a"},
- {"-a;", "-a"},
- {"b-a;", "b - a"},
- {"~a;", "~a"},
- {"b~a;", "b ~ a"},
- {"*a;", "*a"},
- {"b*a;", "b * a"},
- {"++a;", "++a"},
- {"a++;", "a++"},
- {"--a;", "--a"},
- {"a--;", "a--"},
- {"!a--;", "!a--"},
- {"`a` `b`;", "`a` `b`"},
- {"__LINE__ is __DUMB__;", "__LINE__ is __DUMB__"},
- {"i!();", "i!()"},
- {"new class (1) T {};", "new class(1) T {\n}"},
- {"mixin(hi);", "mixin(hi)"},
- {"(int*).max;", "(int*).max"},};
- String[][] expressions2 = {
- {"a ^^ b;", "a ^^ b"},
- {"a ^^= b;", "a ^^= b"},
- {"__traits(me);", "__traits(me)"},
- {"__traits(me,you);", "__traits(me, you)"},
- {"__traits(me,you,us);", "__traits(me, you, us)"},
- {"q{ /*doh*/ }c;", "q{ /*doh*/ }c"},
- {"a ! in b;", "a !in b"},
- {"is(I J == K, L);", "is(I J == K, L)"},
- {"is(I J == K, L, M);", "is(I J == K, L, M)"},
- {"i!i;", "i!i"},
- {"to!int(`1`);", "to!int(`1`)"},};
- String[][] statements = {
- {"int i = 0;", "int i = 0;"},
- {"int i = 0, b = 1, c = 2;", "int i = 0, b = 1, c = 2;"},
- {"int* i = 1;", "int* i = 1;"},
- {"int delegate(int)* i = 1;", "int delegate(int)* i = 1;"},
- {"int delegate(int) delegate(double,int) i = 1;", "int delegate(int) delegate(double, int) i = 1;"},
- {"int [int*] i = 1;", "int[int*] i = 1;"},
- {"int[3] [ 4] i = 1;", "int[3][4] i = 1;"},
- {"int[] *i = 1;", "int[]* i = 1;"},
- {"typeof(1)[] i = 1;", "typeof(1)[] i = 1;"},
- {"MAHBIGLABEL: i;", "MAHBIGLABEL: i;"},
- {"mixin(\"It's a trap!\");", "mixin(\"It's a trap!\");"},
- {"mixin I.I!(I);", "mixin I.I!(I);"},
- {"mixin .I!(I);", "mixin .I!(I);"},
- {"mixin .I.I!(I);", "mixin .I.I!(I);"},
- {"mixin typeof(J).I.I!(I);", "mixin typeof(J).I.I!(I);"},
- {"mixin typeof(J).I.I!(I);", "mixin typeof(J).I.I!(I);"},
- {"mixin I.I!(I) FOO;", "mixin I.I!(I) FOO;"},
- {"mixin .I.I!(I) FOO;", "mixin .I.I!(I) FOO;"},
- {"mixin typeof(J).I.I!(I) FOO;", "mixin typeof(J).I.I!(I) FOO;"},
- {"abstract class X{}", "abstract class X {\n}"},
- {"abstract class X{int i;}", "abstract class X {\n int i;\n}"},
- {"static assert(1,-1);", "static assert(1, -1);"},
- {"static assert (1);", "static assert(1);"},
- {"version(1){ int i; };", "version(1) {\n int i;\n}"},
- {"version(i){ int i; };", "version(i) {\n int i;\n}"},
- {"version(i){ int i; }else{ int j;};", "version(i) {\n int i;\n} else {\n int j;\n}"},
- {"version(i){ int i; }else version(j){ int j;};", "version(i) {\n int i;\n} else version(j) {\n int j;\n}"},
- {"version(i) int i = 0;;", "version(i) int i = 0;"},
- {"debug{ int i; };", "debug {\n int i;\n}"},
- {"debug(1){ int i; };", "debug(1) {\n int i;\n}"},
- {"debug(i){ int i; };", "debug(i) {\n int i;\n}"},
- {"debug(i){ int i; }else{ int j;};", "debug(i) {\n int i;\n} else {\n int j;\n}"},
- {"debug(i){ int i; }else debug(j){ int j;};", "debug(i) {\n int i;\n} else debug(j) {\n int j;\n}"},
- {"static if(i){ int i; };", "static if(i) {\n int i;\n}"},
- {"static if(i){ int i; };", "static if(i) {\n int i;\n}"},
- {"static if(i){ int i; }else{ int j;};", "static if(i) {\n int i;\n} else {\n int j;\n}"},
- {"static if(i){ int i; }else static if(j){ int j;};", "static if(i) {\n int i;\n} else static if(j) {\n int j;\n}"},
- {"if(i){};", "if(i) {\n}"},
- {"if(int i = 0) {};", "if(int i = 0) {\n}"},
- {"if(auto i = 0){};", "if(auto i = 0) {\n}"},
- {"if(i){}else{};", "if(i) {\n} else {\n}"},
- {"if(i){}else if(j){ };", "if(i) {\n} else if(j) {\n}"},
- {"while(true){ true++; };", "while(true) {\n true++;\n}"},
- {"while(true) true++; ;", "while(true) true++;"},
- {"do{ true++; }while(true);", "do {\n true++;\n} while(true);"},
- {"do true++; while(true);", "do true++;\nwhile(true);"},
- {"for(;;){ writeln(i); writeln(i+1);};",
- "for(;;) {\n writeln(i);\n writeln(i + 1);\n}"
- },
- {"for(int i=0;;){ writeln(i); writeln(i+1);};",
- "for(int i = 0;;) {\n writeln(i);\n writeln(i + 1);\n}"
- },
- {"for(;i < 10;){ writeln(i); writeln(i+1);};",
- "for(; i < 10;) {\n writeln(i);\n writeln(i + 1);\n}"
- },
- {"for(;;i++){ writeln(i); writeln(i+1);};",
- "for(;; i++) {\n writeln(i);\n writeln(i + 1);\n}"
- },
- {"for(int i =0; i<10; i ++){ writeln(i); writeln(i+1);};",
- "for(int i = 0; i < 10; i++) {\n writeln(i);\n writeln(i + 1);\n}"
- },
- {"for(;;) i++;;", "for(;;) i++;"},
- {"for({} i < 10; i++) writeln(c);;",
- "for({\n} i < 10; i++) writeln(c);"
- },
- {"for({int i =1; char c = 'a';} i < 10; i++) writeln(c);;",
- "for({\n int i = 1;\n char c = 'a';\n} i < 10; i++) writeln(c);"
- },
- {"foreach(i;j) i++;;", "foreach(i; j) i++;"},
- {"foreach(ref i;j) i++;;", "foreach(ref i; j) i++;"},
- {"foreach(inout i;j) i++;;", "foreach(inout i; j) i++;"},
- {"foreach(int* i;j) i++;;", "foreach(int* i; j) i++;"},
- {"foreach(ref int* i;j) i++;;", "foreach(ref int* i; j) i++;"},
- {"foreach(i;j){i++;};", "foreach(i; j) {\n i++;\n}"},
- {"foreach_reverse(i;j) i++;;", "foreach_reverse(i; j) i++;"},
- {"switch(i){};", "switch(i) {\n}"},
- {"switch(i){ case 1,2: i++;};", "switch(i) {\n case 1, 2: i++;\n}"},
- {"switch(i){ case 1,2: i++; \nj--;};", "switch(i) {\n case 1, 2:\n i++;\n j--;\n}"},
- {"default:{ throw new Exception();};", "default: {\n throw new Exception();\n}"},
- {"switch(i){default: return -1;};", "switch(i) {\n default: return -1;\n}"},
- {"continue i;", "continue i;"},
- {"continue;", "continue;"},
- {"break;", "break;"},
- {"return;", "return;"},
- {"while(true) continue i;;", "while(true) continue i;"},
- {"while(true) break i;;", "while(true) break i;"},
- {"while(true) return i;;", "while(true) return i;"},
- {"while(true) goto i;;", "while(true) goto i;"},
- {"while(true) goto default;;", "while(true) goto default;"},
- {"while(true) goto case ;;", "while(true) goto case;"},
- {"while(true) goto case 1;;", "while(true) goto case 1;"},
- {"with(i){};", "with(i){\n}"},
- {"with(i)i++;", "with(i) i++;"},
- {"synchronized(i)i++;", "synchronized(i) i++;"},
- {"synchronized{i++;}", "synchronized {\n i++;\n}"},
- {"try{ i++; }catch{ i--; };", "try {\n i++;\n} catch {\n i--;\n}"},
- {"try{ i++; }catch(Exception ex){ i--; };", "try {\n i++;\n} catch(Exception ex) {\n i--;\n}"},
- {"try{ i++; }catch(Exception ex){ i--; }finally{};", "try {\n i++;\n} catch(Exception ex) {\n i--;\n} finally {\n}"},
- {"try{ i++; }finally{ i--; };", "try {\n i++;\n} finally {\n i--;\n}"},
- {"while(true) throw i;;", "while(true) throw i;"},
- {"scope(success) i++;", "scope(success) i++;"},
- {"asm{ cmp EAX 1;}", "asm {\n cmp EAX 1;\n}"}, //no, I don't know jack about asm syntax
- {"pragma(msg);", "pragma(msg);"},
- {"pragma(msg,\"hi!\");", "pragma(msg, \"hi!\");"},
- {"{};", "{\n}"},
- {"volatile int i;", "volatile int i;"},
- {"volatile{ int i;};", "volatile {\n int i;\n}"},
- {"LABEL: int i = 0;;", "LABEL: int i = 0;"},
- {"LABEL: ;;", "LABEL:;"},};
- String[][] statements2 = {
- {"final switch(i){};", "final switch(i) {\n}"},
- {"case 1: .. case 2: i++;", "case 1:\n..\ncase 2: i++;"},
- {"foreach(i; 1 .. 10) i++;", "foreach(i; 1 .. 10) i++;"},};
- String[][] decls = {
- {"enum I{}", "enum I {\n}"},
- {"enum I;", "enum I;"},
- {"enum I:int{}", "enum I: int {\n}"},
- {"enum {}", "enum {\n}"},
- {"enum :int{}", "enum: int {\n}"},
- {"enum I{ a}", "enum I {\n a,\n}"},
- {"enum I{ a,}", "enum I {\n a,\n}"},
- {"enum I{ a,b}", "enum I {\n a,\n b,\n}"},
- {"enum I{ a=1}", "enum I {\n a = 1,\n}"},
- {"enum I{ a = 1, b}", "enum I {\n a = 1,\n b,\n}"},
- {"class I{}", "class I {\n}"},
- {"class I:B{}", "class I: B {\n}"},
- {"class I(T){}", "class I(T) {\n}"},
- {"class I(T):B{}", "class I(T): B {\n}"},
- {"class I(T):B { static assert(green);}", "class I(T): B {\n static assert(green);\n}"},
- {"class I;", "class I;"},
- {"class I:B,C,D{}", "class I: B, C, D {\n}"},
- {"class I:private B{}", "class I: private B {\n}"},
- {"class I:B.C.D{}", "class I: B.C.D {\n}"},
- {"class I:B.C!(D){}", "class I: B.C!(D) {\n}"},
- {"interface I{}", "interface I {\n}"},
- {"interface I:B{}", "interface I: B {\n}"},
- {"interface I(T){}", "interface I(T) {\n}"},
- {"interface I(T):B{}", "interface I(T): B {\n}"},
- {"interface I(T):B{ static assert(green);}", "interface I(T): B {\n static assert(green);\n}"},
- {"interface I;", "interface I;"},
- {"interface I:B,C,D{}", "interface I: B, C, D {\n}"},
- {"interface I:private B{}", "interface I: private B {\n}"},
- {"interface I:B.C.D{}", "interface I: B.C.D {\n}"},
- {"interface I:B.C!(D){}", "interface I: B.C!(D) {\n}"},
- {"struct I{}", "struct I {\n}"},
- {"struct I(T){}", "struct I(T) {\n}"},
- {"struct I;", "struct I;"},
- {"struct{}", "struct {\n}"},
- {"union I{}", "union I {\n}"},
- {"union I(T){}", "union I(T) {\n}"},
- {"union I;", "union I;"},
- {"union{}", "union {\n}"},
- {"import i;", "import i;"},
- {"import i, j;", "import i, j;"},
- {"import i.i.i;", "import i.i.i;"},
- {"import I = i;", "import I = i;"},
- {"static import i;", "static import i;"},
- {"import i:j;", "import i: j;"},
- {"import i:j=k;", "import i: j = k;"},
- {"template T(){}", "template T() {\n}"},
- {"template T(alias i){}", "template T(alias i) {\n}"},
- {"template T(alias i:int){}", "template T(alias i: int) {\n}"},
- {"template T(alias i=int){}", "template T(alias i = int) {\n}"},
- {"template T(i...){}", "template T(i...) {\n}"},
- {"template T(int i:1){}", "template T(int i: 1) {\n}"},
- {"template T(int i=1){}", "template T(int i = 1) {\n}"},
- {"template T(i){}", "template T(i) {\n}"},
- {"template T(i:j){}", "template T(i: j) {\n}"},
- {"template T(i=j){}", "template T(i = j) {\n}"},
- {"template T(i, alias i, int i){}", "template T(i, alias i, int i) {\n}"},
- {"mixin(\"mixin(\\\"hi!\\\");\");", "mixin(\"mixin(\\\"hi!\\\");\");"},
- {"typedef i j;", "typedef i j;"},
- {"typedef deprecated i j;", "typedef deprecated i j;"},
- {"typedef i j =1;", "typedef i j = 1;"},
- {"typedef i j , k;", "typedef i j, k;"},
- {"typedef i j =1 , k=1;", "typedef i j = 1, k = 1;"},
- {"alias i j;", "alias i j;"},
- {"alias static i j;", "alias static i j;"},
- {"alias i j, k, m;", "alias i j, k, m;"},
- {"auto i = 1;", "auto i = 1;"},
- {"auto i = 1, j = 2;", "auto i = 1, j = 2;"},
- {"int i(int j){}", "int i(int j) {\n}"},
- {"int i(lazy int j){}", "int i(lazy int j) {\n}"},
- {"int i(in int j){}", "int i(in int j) {\n}"},
- {"int i(inout int j){}", "int i(inout int j) {\n}"},
- {"int i(out int j){}", "int i(out int j) {\n}"},
- {"int i(int j, int k = 1){}", "int i(int j, int k = 1) {\n}"},
- {"int i(int j, int k ...){}", "int i(int j, int k...) {\n}"},
- {"int i(int j, int ...){}", "int i(int j, int...) {\n}"},
- {"int i(int j, int ){}", "int i(int j, int) {\n}"},
- {"int i(...){}", "int i(...) {\n}"},
- {"int i() body{}", "int i()\nbody {\n}"},
- {"int i() in{}out{}body{}", "int i()\nin {\n} out {\n} body {\n}"},
- {"int i() in{}out(result){}body{}", "int i()\nin {\n} out(result) {\n} body {\n}"},
- {"this(){}", "this() {\n}"},
- {"this(int i){}", "this(int i) {\n}"},
- {"~this(){}", "~this() {\n}"},
- {"invariant{}", "invariant() {\n}"},
- {"unittest{}", "unittest {\n}"},
- {"new(){}", "new() {\n}"},
- {"new(int i){}", "new(int i) {\n}"},
- {"delete(){}", "delete() {\n}"},
- {"delete(int i){}", "delete(int i) {\n}"},
- {"static this(){}", "static this() {\n}"},
- {"static ~this(){}", "static ~this() {\n}"},
- {"static assert(i);", "static assert(i);"},
- {"static assert(i,j);", "static assert(i, j);"},
- {"static if(i){}", "static if(i) {\n}"},
- {"static if(i){}else {}", "static if(i) {\n} else {\n}"},
- {"private{}", "private{\n}"},
- {"static{}", "static{\n}"},
- {"static{int i;}", "static{\n int i;\n}"},
- {"private:int i;", "private:\n int i;"},
- {"public export:int i;", "public export:\n int i;"},
- {"static: int i;", "static:\n int i;"},
- {"static private: int i;", "static private:\n int i;"},
- {"align(16): int i;", "align(16):\n int i;"},
- {"align: int i;", "align:\n int i;"},
- {"align int i;", "align int i;"},
- {"export: int i;", "export:\n int i;"},
- {"private extern: int i;", "private extern:\n int i;"},
- {"private extern(C++): int i;", "private extern(C++):\n int i;"},
- {"private extern(Windows): int i;", "private extern(Windows):\n int i;"},
- {"pragma(msk): int i;", "pragma(msk):\n int i;"},
- {"pragma(msk,msy): int i;", "pragma(msk, msy):\n int i;"},
- {"debug = I;", "debug = I;"},
- {"debug = 1;", "debug = 1;"},
- {"version = i;", "version = i;"},
- {"version = 1;", "version = 1;"},
- {"debug{}", "debug {\n}"},
- {"debug(i){}", "debug(i) {\n}"},
- {"version(i){}", "version(i) {\n}"},
- {"int[] i = [1,2,3,];", "int[] i = [1, 2, 3];"},
- {"int[] i = [];", "int[] i = [];"},
- {"int[] i = [0:1,10:2,3,];", "int[] i = [0: 1, 10: 2, 3];"},
- {"Struct s = {1,2,3};", "Struct s = {1, 2, 3};"},
- {"Struct s = {};", "Struct s = {};"},
- {"Struct s = {i:1,J:2,3};", "Struct s = {i: 1, J: 2, 3};"},
- {"Struct[] s = [{1,2,3}, {4,5,6}];", "Struct[] s = [{1, 2, 3}, {4, 5, 6}];"},
- {"int[] i = void;", "int[] i = void;"},
- {".i* k = 1;", ".i* k = 1;"},
- {".i.i* k = 1;", ".i.i* k = 1;"},
- {"typeof(i).i.i* k = 1;", "typeof(i).i.i* k = 1;"},
- {"int[0..2] i = (1,2);", "int[0 .. 2] i = (1, 2);"},
- {"int (*i)(int) = cast(int(*)(int))function int(int){return 1;};", "int (*i)(int) = cast(int (*)(int)) function int(int){return 1;};"},};
- String[][] decls2 = {
- {"@property abstract auto int i;", "@property abstract auto int i;"},
- {"abstract private int i;", "abstract private int i;"},
- {"@Anno private int i;", "@Anno private int i;"},
- {"const deprecated enum int i;", "const deprecated enum int i;"},
- {"final __gshared immutable int i;", "final __gshared immutable int i;"},
- {"inout nothrow override pure int i;", "inout nothrow override pure int i;"},
- {"ref scope shared int i;", "ref scope shared int i;"},
- {"static synchronized __thread int i;", "static synchronized __thread int i;"},
- {"auto a(int i){}", "auto a(int i) {\n}"},
- {"enum I{ int i = 1,}", "enum I {\n int i = 1,\n}"},
- {"mixin template T(){}", "mixin template T() {\n}"},
- {"template T(this I){}", "template T(this I) {\n}"},
- {"template T(alias int i){}", "template T(alias int i) {\n}"},
- {"version(unittest){}", "version(unittest) {\n}"},
- {"class X(T) if(is(T == int)){}", "class X(T) if(is(T == int)) {\n}"},
- {"alias i this;", "alias i this;"},
- {"const(int) i;", "const(int) i;"},
- {"const shared(int) i;", "const shared(int) i;"},
- {"const (shared int) i;", "const(shared int) i;"},
- {"const (shared(int)) i;", "const(shared(int)) i;"},
- {"int i(int j) nothrow {}", "int i(int j) nothrow {\n}"},
- {"int i(int j) pure nothrow {}", "int i(int j) pure nothrow {\n}"},
- {"int i(I)(int j) nothrow if(is(I)) {}", "int i(I)(int j) nothrow if(is(I)) {\n}"},};
- for (String[] raw_formatted : expressions) {
- AST t = expression(raw_formatted[0]);
- String s = Formatter.format(t);
- // System.out.println(raw_formatted[1] + " " + s);
- assertEquals(raw_formatted[1], s);
- assertEquals(raw_formatted[1], Formatter.format2(t));
- }
- for (String[] raw_formatted : expressions2) {
- AST t = expression2(raw_formatted[0]);
- String s = Formatter.format2(t);
- // System.out.println(raw_formatted[1] + " " + s);
- assertEquals(raw_formatted[1], s);
- }
- for (String[] raw_formatted : statements) {
- AST t = statement(raw_formatted[0]);
- String s = Formatter.format(t);
- System.out.println(MessageFormat.format("\"{0}\" vs \"{1}\"", raw_formatted[1],s));
- assertEquals(raw_formatted[1], s);
- assertEquals(raw_formatted[1], Formatter.format2(t));
- }
- for (String[] raw_formatted : statements2) {
- AST t = statement2(raw_formatted[0]);
- String s = Formatter.format2(t);
- // System.out.println(MessageFormat.format("\"{0}\" vs \"{1}\"", raw_formatted[1],s));
- assertEquals(raw_formatted[1], s);
- }
- for (String[] raw_formatted : decls) {
- AST t = declDef(raw_formatted[0]);
- String s = Formatter.format(t);
- if (!s.equals(raw_formatted[1])) {
- System.out.println(MessageFormat.format("\"{0}\" vs \"{1}\"", raw_formatted[1], s));
- // Visitor.dump(t);
- }
- assertEquals(raw_formatted[1], s);
- assertEquals(raw_formatted[1], Formatter.format2(t));
- }
- for (String[] raw_formatted : decls2) {
- AST t = declDef2(raw_formatted[0]);
- String s = Formatter.format2(t);
- if (!s.equals(raw_formatted[1])) {
- System.out.println(MessageFormat.format("\"{0}\" vs \"{1}\"", raw_formatted[1], s));
- // Visitor.dump(t);
- }
- assertEquals(raw_formatted[1], s);
- }
- CodeStyle b4foreachParenT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeForeachParen() {
- return true;
- }
- };
- CodeStyle b4foreachParenF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeForeachParen() {
- return false;
- }
- };
- CodeStyle b4versionParenT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeVersionParen() {
- return true;
- }
- };
- CodeStyle b4versionParenF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeVersionParen() {
- return false;
- }
- };
- CodeStyle b4debugParenT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeDebugParen() {
- return true;
- }
- };
- CodeStyle b4debugParenF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeDebugParen() {
- return false;
- }
- };
- CodeStyle b4catchParenT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatchParen() {
- return true;
- }
- };
- CodeStyle b4catchParenF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatchParen() {
- return false;
- }
- };
- CodeStyle b4catchLBraceT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatchLeftBrace() {
- return true;
- }
- };
- CodeStyle b4catchLBraceF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatchLeftBrace() {
- return false;
- }
- };
- CodeStyle b4tryLBraceT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeTryLeftBrace() {
- return true;
- }
- };
- CodeStyle b4tryLBraceF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeTryLeftBrace() {
- return false;
- }
- };
- CodeStyle b4catchT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatch() {
- return true;
- }
- };
- CodeStyle b4catchF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceBeforeCatch() {
- return false;
- }
- };
- CodeStyle rndUnaryT = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceAroundUnaryOps() {
- return true;
- }
- };
- CodeStyle rndUnaryF = new CodeStyle.DefaultCodeStyle(1) {
- @Override
- public boolean spaceAroundUnaryOps() {
- return false;
- }
- };
- Object[] stmts = new Object[]{
- new Object[]{"foreach(i; j){};", b4foreachParenT, "foreach (i; j) {\n}"},
- new Object[]{"foreach(i; j){};", b4foreachParenF, "foreach(i; j) {\n}"},
- new Object[]{"foreach_reverse(i; j){};", b4foreachParenT, "foreach_reverse (i; j) {\n}"},
- new Object[]{"foreach_reverse(i; j){};", b4foreachParenF, "foreach_reverse(i; j) {\n}"},
- new Object[]{"version(i){};", b4versionParenT, "version (i) {\n}"},
- new Object[]{"version(i){};", b4versionParenF, "version(i) {\n}"},
- new Object[]{"debug(i){};", b4debugParenT, "debug (i) {\n}"},
- new Object[]{"debug(i){};", b4debugParenF, "debug(i) {\n}"},
- new Object[]{"debug{};", b4debugParenT, "debug {\n}"},
- new Object[]{"debug{};", b4debugParenF, "debug {\n}"},
- new Object[]{"try{}catch(Exception e){}", b4catchLBraceT, "try {\n} catch(Exception e) {\n}"},
- new Object[]{"try{}catch(Exception e){}", b4catchLBraceF, "try {\n} catch(Exception e){\n}"},
- new Object[]{"try{}catch(Exception e){}", b4catchT, "try {\n} catch(Exception e) {\n}"},
- new Object[]{"try{}catch(Exception e){}", b4catchF, "try {\n}catch(Exception e) {\n}"},
- new Object[]{"try{}catch(Exception e){}", b4tryLBraceT, "try {\n} catch(Exception e) {\n}"},
- new Object[]{"try{}catch(Exception e){}", b4tryLBraceF, "try{\n} catch(Exception e) {\n}"},
- new Object[]{"i++;", rndUnaryT, "i ++"},
- new Object[]{"i++;", rndUnaryF, "i++"},
- new Object[]{"j--;", rndUnaryT, "j --"},
- new Object[]{"j--;", rndUnaryF, "j--"},
- new Object[]{"++k;", rndUnaryT, "++ k"},
- new Object[]{"++k;", rndUnaryF, "++k"},
- new Object[]{"--l;", rndUnaryT, "-- l"},
- new Object[]{"--l;", rndUnaryF, "--l"},
- new Object[]{"*l;", rndUnaryT, "* l"},
- new Object[]{"*l;", rndUnaryF, "*l"},
- new Object[]{"&l;", rndUnaryT, "& l"},
- new Object[]{"&l;", rndUnaryF, "&l"},
- };
- for (Object ob : stmts) {
- String code = (String) (((Object[]) ob)[0]);
- CodeStyle style = (CodeStyle) (((Object[]) ob)[1]);
- String expected = (String) (((Object[]) ob)[2]);
- AST t = statement(code);
- Formatter f = new Formatter(style);
- f.visit(t);
- String result = f.getString();
- assertEquals(expected, result);
- }
- }
- }