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"
19 namespace format {
23 std::string format(llvm::StringRef Code, unsigned Offset, unsigned Length,
44 format(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) {
45 return format(Code, 0, Code.size(), Style);
95 EXPECT_EQ(Code.str(), format(messUp(Code), Style));
123 EXPECT_EQ(";", format(";"));
127 EXPECT_EQ("int i;", format(" int i;"));
128 EXPECT_EQ("\nint i;", format(" \n\t \r int i;"));
129 EXPECT_EQ("int i;\nint j;", format(" int i; int j;"));
130 EXPECT_EQ("int i;\nint j;", format(" int i;\n int j;"));
134 EXPECT_EQ("int i;", format("int\ni;"));
138 EXPECT_EQ("{\n {\n {}\n }\n}", format("{{{}}}"));
156 format("if(a){f();}"));
161 format("if (a) {\n"
168 EXPECT_EQ("int a;\nint b;", format("int a; \nint b;", 0, 0, getLLVMStyle()));
169 EXPECT_EQ("int a;", format("int a; "));
170 EXPECT_EQ("int a;\n", format("int a; \n \n \n "));
172 format("int a; \nint b; ", 0, 0, getLLVMStyle()));
177 format("int b;\n int a;", 7, 0, getLLVMStyle()));
179 format("int b;\n int a;", 6, 0, getLLVMStyle()));
184 format("#define A \\\n"
191 format("#define A \\\n"
199 format("int a;\n \n\n int b;", 7, 0, getLLVMStyle()));
201 format("int a;\n \n\n int b;", 9, 0, getLLVMStyle()));
210 format(
549 format("void f() { // This does something ..\n"
556 format("void f() { // This does something ..\n"
562 format("int i;\\\n// single line trailing comment"));
583 EXPECT_EQ("// comment", format("// comment "));
585 format("int aaaaaaa, bbbbbbb; // comment ",
594 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , /* Trailing comment for aa... */\n"
599 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \n"
617 format(" /*\n"
629 format("class C {\n"
641 format(" /*\n"
649 format(" /*\n"
661 format("static SomeType type = { aaaaaaaaaaaaaaaaaaaa , /* comment */\n"
695 format("S s = {\n"
702 EXPECT_EQ("S s = { a, b };", format("S s = {\n"
874 // FIXME: Format like enums if the static initializer does not fit on a line.
948 format(" # 123 \"A string literal\""));
949 EXPECT_EQ("#;", format("#;"));
955 format("# \\\n line \\\n 42 \\\n \"test\"\n"));
956 EXPECT_EQ("#define A B\n", format("# \\\n define \\\n A \\\n B\n",
962 format("# \\\n line \\\n 42 \\\n \"test\""));
963 EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B"));
987 format(" // some comment\n"
996 TEST_F(FormatTest, LayoutSingleHash) { EXPECT_EQ("#\na;", format("#\na;")); }
1003 format("#define A c; e;\n"
1008 TEST_F(FormatTest, LayoutRemainingTokens) { EXPECT_EQ("{}", format("{}")); }
1012 format("# define A b;", 11, 2, getLLVMStyleWithColumns(11)));
1019 format("int x,\n#define A\ny;"));
1046 EXPECT_EQ("#define A b;", format("#define A \\\n"
1054 format("#define A \\\n"
1063 format("#define A \\\n"
1085 EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}"));
1094 format("#define A { {\nint i;", getLLVMStyleWithColumns(11)));
1096 format("#define A } }\nint i;", getLLVMStyleWithColumns(11)));
1102 format("#define A \\\nint i;\\\n int j;", getLLVMStyleWithColumns(11)));
1121 format(" #define ALooooooooooooooooooooooooooooooooooooooongMacro("
1133 format("int\n#define A\na;"));
1150 format(" functionCall ( {int i;} );"));
1156 format(" SOME_MACRO {int i;} int i;"));
1171 EXPECT_EQ("{}", format("{}"));
1567 " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
1622 format("fun + \"1243\" /* comment */\n"
1629 format("aaaaaa ="
1845 EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A> >> a;", getGoogleStyle()));
1846 EXPECT_EQ("A<A<A<A>>> a;", format("A<A<A<A>> > a;", getGoogleStyle()));
2047 format("int *a;\n"
2054 format("int* a;\n"
2061 format("int *a;\n"
2226 EXPECT_EQ("void f() { return }", format("void f ( ) { return }"));
2231 format("void f ( ) { if ( a ) return }"));
2232 EXPECT_EQ("namespace N { void f() }", format("namespace N { void f() }"));
2237 format("namespace N { void f( ) { } void g( ) }"));
2294 EXPECT_EQ("{\n{}\n", format("{\n{\n}\n"));
2295 EXPECT_EQ("{\n {}\n", format("{\n {\n}\n"));
2296 EXPECT_EQ("{\n {}\n", format("{\n {\n }\n"));
2297 EXPECT_EQ("{\n {}\n }\n}\n", format("{\n {\n }\n }\n}\n"));
2304 format("{\n"
2403 EXPECT_EQ("#error 1", format(" # error 1"));
2404 EXPECT_EQ("#warning 1", format(" # warning 1"));
2414 format("if (true)\nreturn 42;", AllowsMergedIf));
2462 format("/* *//* */ /* */\n/* *//* */ /* */"));
2463 EXPECT_EQ("/* */ a /* */ b;", format(" /* */ a/* */ b;"));
2469 format("#define A /* */ b\n"
2477 format("#define A\n"
2488 format("someFunction (1, /* comment 1 */\n"
2500 format(
2508 format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
2518 format("#define A { \\\n"
2527 format("#define A { \\\n"
2568 format("-(NSUInteger)indexOfObject:(id)anObject;"));
2569 EXPECT_EQ("- (NSInteger)Mthod1;", format("-(NSInteger)Mthod1;"));
2570 EXPECT_EQ("+ (id)Mthod2;", format("+(id)Mthod2;"));
2572 format("-(NSInteger)Method3:(id)anObject;"));
2574 format("-(NSInteger)Method4:(id)anObject;"));
2576 format("-(NSInteger)Method5:(id)anObject:(id)AnotherObject;"));
2578 format("- (id)Method6:(id)A:(id)B:(id)C:(id)D;"));
2581 format(
2990 EXPECT_EQ("@interface", format("@ interface"));
3071 format("{\n"
3084 format("{\n"
3097 format("{\n"
3112 format("{\n"
3124 format(" {\n"
3130 format("void f() {}\n"
3138 format("\"some text other\";", getLLVMStyleWithColumns(12)));
3144 format("#define A \"some text other\";", getLLVMStyleWithColumns(12)));
3150 format("#define A \"so text other\";", getLLVMStyleWithColumns(12)));
3153 format("\"some text\"", getLLVMStyleWithColumns(1)));
3155 format("\"some text\"", getLLVMStyleWithColumns(11)));
3158 format("\"some text\"", getLLVMStyleWithColumns(10)));
3161 format("\"some text\"", getLLVMStyleWithColumns(7)));
3164 format("\"some text\"", getLLVMStyleWithColumns(6)));
3168 format("\"some tex and\"", getLLVMStyleWithColumns(6)));
3172 format("\"some/tex/and\"", getLLVMStyleWithColumns(6)));
3177 format("variable = \"long string literal\";",
3185 format("variable = f(\"long string literal\", short, "
3191 format("f(\"one two\".split(variable));", getLLVMStyleWithColumns(20)));
3195 format("f(\"one two three four five six seven\"."
3202 format("f(\"some text\", other);", getLLVMStyleWithColumns(10)));
3214 format("\"splitmeatrandompoint\"", getLLVMStyleWithColumns(10)));
3220 format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
3225 format("\"\\a\"", getLLVMStyleWithColumns(3)));
3227 format("\"\\\"", getLLVMStyleWithColumns(2)));
3230 format("\"test\\n\"", getLLVMStyleWithColumns(7)));
3233 format("\"tes\\\\n\"", getLLVMStyleWithColumns(7)));
3236 format("\"\\\\\\\\\\n\"", getLLVMStyleWithColumns(7)));
3238 format("\"\\uff01\"", getLLVMStyleWithColumns(7)));
3241 format("\"\\uff01test\"", getLLVMStyleWithColumns(8)));
3243 format("\"\\Uff01ff02\"", getLLVMStyleWithColumns(11)));
3246 format("\"\\x000000000001next\"", getLLVMStyleWithColumns(16)));
3248 format("\"\\x000000000001next\"", getLLVMStyleWithColumns(15)));
3250 format("\"\\x000000000001\"", getLLVMStyleWithColumns(7)));
3254 format("\"test\\000000000001\"", getLLVMStyleWithColumns(9)));
3257 format("\"test\\000000000001\"", getLLVMStyleWithColumns(10)));
3259 format("R\"(\\x\\x00)\"\n", getLLVMStyleWithColumns(7)));