Home | History | Annotate | Download | only in Format

Lines Matching refs:format

1 //===- unittest/Format/FormatTest.cpp - Formatting unit tests -------------===//
10 #define DEBUG_TYPE "format-test"
12 #include "clang/Format/Format.h"
18 namespace format {
22 std::string format(llvm::StringRef Code, unsigned Offset, unsigned Length,
35 format(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) {
36 return format(Code, 0, Code.size(), Style);
86 EXPECT_EQ(Code.str(), format(messUp(Code), Style));
114 EXPECT_EQ(";", format(";"));
118 EXPECT_EQ("int i;", format(" int i;"));
119 EXPECT_EQ("\nint i;", format(" \n\t \r int i;"));
120 EXPECT_EQ("int i;\nint j;", format(" int i; int j;"));
121 EXPECT_EQ("int i;\nint j;", format(" int i;\n int j;"));
125 EXPECT_EQ("int i;", format("int\ni;"));
129 EXPECT_EQ("{\n {\n {}\n }\n}", format("{{{}}}"));
147 format("if(a){f();}"));
152 format("if (a) {\n"
159 EXPECT_EQ("int a;\nint b;", format("int a; \nint b;", 0, 0, getLLVMStyle()));
160 EXPECT_EQ("int a;", format("int a; "));
161 EXPECT_EQ("int a;\n", format("int a; \n \n \n "));
163 format("int a; \nint b; ", 0, 0, getLLVMStyle()));
168 format("int b;\n int a;", 7, 0, getLLVMStyle()));
170 format("int b;\n int a;", 6, 0, getLLVMStyle()));
175 format("#define A \\\n"
182 format("#define A \\\n"
190 format("int a;\n \n\n int b;", 7, 0, getLLVMStyle()));
192 format("int a;\n \n\n int b;", 9, 0, getLLVMStyle()));
199 format("class C {\n"
213 format("void f() {\n"
228 format("namespace {\n"
236 format("namespace {\n"
248 format(
292 EXPECT_EQ("if (a) return;", format("if(a)\nreturn;", 7, 1, AllowsMergedIf));
294 format("if(a)\nreturn; // comment", 20, 1, AllowsMergedIf));
637 format("#include \\\n"
665 format("void f() { // This does something ..\n"
674 format("class C{void f() { // This does something ..\n"
681 format("int i;\\\n// single line trailing comment"));
703 format("D(a, {\n"
711 format("lineWith(); // comment\n"
717 format("lineWith(); // comment\n"
724 format("lineWith(); // comment\n"
730 format("lineWith();\n"
736 format("// first\n"
743 format("f();\n"
752 format("int a; // comment\n"
758 format("int a; // comment\n"
765 format("int aaaaaa; // comment\n"
772 EXPECT_EQ("// comment", format("// comment "));
774 format("int aaaaaaa, bbbbbbb; // comment ",
783 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \\\n/* Trailing comment for aa... */\n"
788 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \n"
795 format("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
815 format(" /*\n"
827 format("class C {\n"
839 format(" /*\n"
847 format(" /*\n"
854 format("int i; /* Comment with empty...\n"
862 format("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
874 format("void ffffffffffff(int aaaaaaaa, int bbbbbbbb, int cccccccccccc)\n"
886 format("void ffffffffff(int aaaaa /* test */);",
894 format("// A comment that doesn't fit on one line",
899 format("// a b c d e f g h i j k",
904 format("\\\n// a b c d e f g h i j k",
909 format("if (true) // A comment that doesn't fit on one line ",
912 format("// Don't_touch_leading_whitespace",
916 format("//Add leading whitespace", getLLVMStyleWithColumns(20)));
917 EXPECT_EQ("// whitespace", format("//whitespace", getLLVMStyle()));
920 format("//Even if it makes the line exceed the column limit",
922 EXPECT_EQ("//--But not here", format("//--But not here", getLLVMStyle()));
927 format("// A comment before a macro definition\n"
934 format("void ffffff(\n"
941 format("//\t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
949 format("// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
955 format("int a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
965 format("int a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
976 format("if (xxx == yyy && // aaaaaaaaaaaa bbbbbbbbb\n"
983 format("if (xxxxxxxxxx == yyy && // aaaaaa bbbbbbbb cccc\n"
990 format("if (xxxxxxxxxx && yyy || // aaaaaa bbbbbbbb cccc\n"
996 format("fffffffff(&xxx, // aaaaaaaaaaaa bbbbbbbbbbb\n"
1006 format("#define A(x) /* \\\n"
1016 format("#define A( \\\n"
1026 format("namespace {}\n // Test\n#define A"));
1028 format("namespace {}\n /* Test */\n#define A"));
1030 format("namespace {}\n /* Test */ #define A"));
1039 format("/* "
1049 format("/* a b c d e f g h i j k */",
1055 format("\\\n/* a b c d e f g h i j k */",
1062 format("/*\n"
1073 format("/* \n"
1084 format("/*\n"
1093 format("/*\n"
1105 format("{\n"
1122 format("{\n"
1137 format(" /*\n"
1146 format("{\n"
1156 format("/* A comment before a macro definition */\n"
1167 format(" /* some comment\n"
1178 format(" /* \n"
1193 format("#define X \\\n"
1205 format("#define X \\\n"
1215 format("#define X \\\n"
1228 format("static SomeType type = { aaaaaaaaaaaaaaaaaaaa , /* comment */\n"
1262 format("S s = {\n"
1276 format("S s = {\n"
1295 format("#if 0\n"
1303 format("#if false\n"
1316 format("enum E {\n"
1334 format("enum F {\n"
1354 format("enum G {\n"
1374 format("enum H {\n"
1393 format("enum I {\n"
1413 format("enum J {\n"
1463 format("class A {\n"
1562 format("#ifndef HEADER_GUARD\n"
1577 format("namespace out {\n"
1592 format("namespace out {\n"
1674 EXPECT_EQ("S s = { a, b };", format("S s = {\n"
1769 format(" # 123 \"A string literal\""));
1770 EXPECT_EQ("#;", format("#;"));
1776 format("# \\\n line \\\n 42 \\\n \"test\"\n"));
1777 EXPECT_EQ("#define A B\n", format("# \\\n define \\\n A \\\n B\n",
1783 format("# \\\n line \\\n 42 \\\n \"test\""));
1784 EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B"));
1808 format(" // somecomment\n"
1817 TEST_F(FormatTest, LayoutSingleHash) { EXPECT_EQ("#\na;", format("#\na;")); }
1824 format("#define A c; e;\n"
1829 TEST_F(FormatTest, LayoutRemainingTokens) { EXPECT_EQ("{}", format("{}")); }
1837 format("int i;\n"
1848 format("int i;\n"
1860 format("int x,\n#define A\ny;"));
1887 EXPECT_EQ("#define A b;", format("#define A \\\n"
1895 format("#define A \\\n"
1904 format("#define A \\\n"
1929 format("class A : public QObject {\n"
1938 format("SOME_MACRO\n"
1944 format("HTTP\nf();"));
1946 format("MACRO\nf();"));
1951 format("class A : public QObject {\n"
1965 format(" INITIALIZE_PASS_BEGIN(ScopDetection, \"polly-detect\")\n"
1978 format("int q() {\n"
2004 format("int q() {\n"
2041 format("int q() {\n"
2059 format("class A {\n"
2074 EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}"));
2083 format("#define A { {\nint i;", getLLVMStyleWithColumns(11)));
2085 format("#define A } }\nint i;", getLLVMStyleWithColumns(11)));
2091 format("#define A \\\nint i;\\\n int j;", getLLVMStyleWithColumns(11)));
2092 EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();"));
2096 EXPECT_EQ("/* \\ \\ \\\n*/", format("\\\n/* \\ \\ \\\n*/"));
2115 format(" #define ALooooooooooooooooooooooooooooooooooooooongMacro("
2127 format("int\n#define A\na;", getGoogleStyle()));
2144 format(" functionCall ( {int i;} );"));
2151 format(" functionCall ( {int i;}, aaaa, bbbb, cccc);"));
2163 format(" SOME_MACRO {int i;} int i;"));
2178 EXPECT_EQ("{}", format("{}"));
2712 format("f(g(h(a, // comment\n"
2792 format("aaa(aaaa,\n" // one-per-line
2801 format("aaa(aaaa, aaaa,\n" // bin-packed
2962 " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
3050 format("fun + \"1243\" /* comment */\n"
3057 format("aaaaaa ="
3117 format("x = \"a\\\n"
3125 format("x = \"a\\\n"
3407 EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A> >> a;", getGoogleStyle()));
3408 EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A>> > a;", getGoogleStyle()));
3675 format("int *a;\n"
3682 format("int* a;\n"
3689 format("int *a;\n"
3945 EXPECT_EQ("void f() { return }", format("void f ( ) { return }"));
3950 format("void f ( ) { if ( a ) return }"));
3954 format("namespace N { void f() }"));
3959 format("namespace N { void f( ) { } void g( ) }"));
4021 EXPECT_EQ("{\n{}\n", format("{\n{\n}\n"));
4022 EXPECT_EQ("{\n {}\n", format("{\n {\n}\n"));
4023 EXPECT_EQ("{\n {}\n", format("{\n {\n }\n"));
4024 EXPECT_EQ("{\n {}\n }\n}\n", format("{\n {\n }\n }\n}\n"));
4031 format("{\n"
4184 EXPECT_EQ("#error 1", format(" # error 1"));
4185 EXPECT_EQ("#warning 1", format(" # warning 1"));
4206 format("if (true)\nreturn 42;", AllowsMergedIf));
4254 format("/* *//* */ /* */\n/* *//* */ /* */"));
4255 EXPECT_EQ("/* */ a /* */ b;", format(" /* */ a/* */ b;"));
4261 format("#define A /*123*/ b\n"
4269 format("#define A\n"
4272 EXPECT_EQ("/*\n**\n*/", format("/*\n**\n*/"));
4278 format("/*\n"
4288 format("/*\n"
4301 format("someFunction (1, /* comment 1 */\n"
4313 format(
4321 format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
4330 format("/*\n"
4336 format("/*\n"
4342 format("/*\n"
4347 format("/*\n"
4351 format("/*\n"
4360 format("#define A { \\\n"
4369 format("#define A { \\\n"
4380 format("a = {1111 /* */\n"
4386 format("a = {1111 /* */\n"
4395 format("a = {1111 /* a */\n"
4434 format("-(NSUInteger)indexOfObject:(id)anObject;"));
4435 EXPECT_EQ("- (NSInteger)Mthod1;", format("-(NSInteger)Mthod1;"));
4436 EXPECT_EQ("+ (id)Mthod2;", format("+(id)Mthod2;"));
4438 format("-(NSInteger)Method3:(id)anObject;"));
4440 format("-(NSInteger)Method4:(id)anObject;"));
4442 format("-(NSInteger)Method5:(id)anObject:(id)AnotherObject;"));
4444 format("- (id)Method6:(id)A:(id)B:(id)C:(id)D;"));
4447 format(
4870 EXPECT_EQ("@interface", format("@ interface"));
4960 format("{\n"
4973 format("{\n"
4986 format("{\n"
5001 format("{\n"
5013 format(" {\n"
5019 format("void f() {}\n"
5025 format("int a; // comment\n"
5033 format(" int a;\n"
5041 format("\"some text other\";", getLLVMStyleWithColumns(12)));
5044 format("\\\n\"some text other\";", getLLVMStyleWithColumns(12)));
5050 format("#define A \"some text other\";", getLLVMStyleWithColumns(12)));
5056 format("#define A \"so text other\";", getLLVMStyleWithColumns(12)));
5059 format("\"some text\"", getLLVMStyleWithColumns(1)));
5061 format("\"some text\"", getLLVMStyleWithColumns(11)));
5064 format("\"some text\"", getLLVMStyleWithColumns(10)));
5067 format("\"some text\"", getLLVMStyleWithColumns(7)));
5071 format("\"some text\"", getLLVMStyleWithColumns(6)));
5075 format("\"some tex and\"", getLLVMStyleWithColumns(6)));
5079 format("\"some/tex/and\"", getLLVMStyleWithColumns(6)));
5084 format("variable = \"long string literal\";",
5092 format("variable = f(\"long string literal\", short, "
5099 format("f(g(\"long string literal\"), b);",
5105 format("f(g(\"long string literal\", a), b);",
5110 format("f(\"one two\".split(variable));", getLLVMStyleWithColumns(20)));
5114 format
5121 format("f(\"some text\", other);", getLLVMStyleWithColumns(10)));
5133 format("\"splitmeatrandompoint\"", getLLVMStyleWithColumns(10)));
5139 format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
5145 format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
5152 format("\"split at "
5166 format("aaaaaaaaaaaa(aaaaaaaaaaaaa, \"aaaaaaaaaaaaaaaaaaaaaa "
5172 format("llvm::outs() << "
5183 format("#define A \"some text other\";", AlignLeft));
5191 format("aaaaaaaaaaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
5199 format("u8\"unsupported literal\";", getGoogleStyleWithColumns(15)));
5201 format("u\"unsupported literal\";", getGoogleStyleWithColumns(15)));
5203 format("U\"unsupported literal\";", getGoogleStyleWithColumns(15)));
5205 format("L\"unsupported literal\";", getGoogleStyleWithColumns(15)));
5207 format("R\"x(raw literal)x\";", getGoogleStyleWithColumns(15)));
5211 format("function( \"unterminated,\n"
5217 format("#define x(_a) printf(\"foo\"_a);", getLLVMStyle()));
5223 format("someFunction(\"aaabbbcccdddeeefff\");",
5227 format("someFunction1234567890(\"aaabbbcccdddeeefff\");",
5232 format("someFunction1234567890(\"aaabbbcccdddeeefff\");",
5237 format("someFunction1234567890(\"aaabbbcccdddeeefff\");",
5242 format("someFunction(\"aaabbbcc dddeeefff\");",
5246 format("someFunction(\"aaabbbccc ddeeefff\");",
5251 format("someFunction1234567890(\"aaabb cccdddeeefff\");",
5258 format("#define A string s = \"1234567890\"; int i;",
5264 format("\"\\a\"", getLLVMStyleWithColumns(3)));
5266 format("\"\\\"", getLLVMStyleWithColumns(2)));
5269 format("\"test\\n\"", getLLVMStyleWithColumns(7)));
5272 format("\"tes\\\\n\"", getLLVMStyleWithColumns(7)));
5275 format("\"\\\\\\\\\\n\"", getLLVMStyleWithColumns(7)));
5277 format("\"\\uff01\"", getLLVMStyleWithColumns(7)));
5280 format("\"\\uff01test\"", getLLVMStyleWithColumns(8)));
5282 format("\"\\Uff01ff02\"", getLLVMStyleWithColumns(11)));
5285 format("\"\\x000000000001next\"", getLLVMStyleWithColumns(16)));
5287 format("\"\\x000000000001next\"", getLLVMStyleWithColumns(15)));
5289 format("\"\\x000000000001\"", getLLVMStyleWithColumns(7)));
5293 format("\"test\\000000000001\"", getLLVMStyleWithColumns(9)));
5297 format("\"test\\000000000001\"", getLLVMStyleWithColumns(10)));
5299 format("R\"(\\x\\x00)\"\n", getGoogleStyleWithColumns(7)));
5378 // format(" /*\t \t \n"
5388 // format(" /*\t \t \n"
5395 // format(" \t \t /* some\n"
5405 format("{\n"
5694 format("\"\xce\xe4\xed\xe0\xe6\xe4\xfb \xe2 "
5724 format("\"???????, ? ???????? ?????? ????,\"",
5729 format("\"? ? ? ? ? ? ? ? ? ?\"",
5738 format("// ? ?? ???? ?????; ??? ??????? ?????.",
5744 format("// ??? ???? ? ? ?", getLLVMStyleWithColumns(6)));
5756 format("/* ?????, ??????????? ???????? ? ????\n"
5764 format("/* ??? ???? ? ? ? */", getLLVMStyleWithColumns(6)));
5768 format("/* ???? ???? ???? ???-? */", getLLVMStyleWithColumns(12)));
5806 format(
5841 format("if (aaaaaaaaaaaaaaa\n"
5847 format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style));