diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-24 13:10:59 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-24 13:10:59 +0000 |
commit | ffefb3d1e0b2b5deeee67ec6528371e23b87c623 (patch) | |
tree | 48ded79608569a3364c7c87ffe52c925669b133c /clang/unittests/Format/FormatTest.cpp | |
parent | c467c94e0bf015100d7d3a9dc900cb35689cd2e8 (diff) | |
download | bcm5719-llvm-ffefb3d1e0b2b5deeee67ec6528371e23b87c623.tar.gz bcm5719-llvm-ffefb3d1e0b2b5deeee67ec6528371e23b87c623.zip |
clang-format: Initial (incomplete) support for the WebKit coding style.
This is far from implementing all the rules given by
http://www.webkit.org/coding/coding-style.html
The important new feature is the support for styles that don't have a
column limit. For such styles, clang-format will (at the moment) simply
respect the input's formatting decisions within statements.
llvm-svn: 187033
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ecdb7216ba6..9f41491924e 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5361,6 +5361,11 @@ TEST_F(FormatTest, GetsPredefinedStyleByName) { EXPECT_TRUE(getPredefinedStyle("moZILla", &Styles[2])); EXPECT_TRUE(allStylesEqual(Styles)); + Styles[0] = getWebKitStyle(); + EXPECT_TRUE(getPredefinedStyle("WebKit", &Styles[1])); + EXPECT_TRUE(getPredefinedStyle("wEbKit", &Styles[2])); + EXPECT_TRUE(allStylesEqual(Styles)); + EXPECT_FALSE(getPredefinedStyle("qwerty", &Styles[0])); } @@ -5515,6 +5520,79 @@ TEST_F(FormatTest, SplitsUTF8BlockComments) { format("/* 𝓣𝓮𝓼𝓽 𝔣𝔬𝔲𝔯 𝕓𝕪𝕥𝕖 𝖀𝕿𝕱-𝟠 */", getLLVMStyleWithColumns(12))); } +TEST_F(FormatTest, FormatsWithWebKitStyle) { + FormatStyle Style = getWebKitStyle(); + + // Don't indent in outer namespaces. + verifyFormat("namespace outer {\n" + "int i;\n" + "namespace inner {\n" + "int i;\n" // FIXME: This should be indented. + "} // namespace inner\n" + "} // namespace outer\n" + "namespace other_outer {\n" + "int i;\n" + "}", + Style); + + // Don't indent case labels. + verifyFormat("switch (variable) {\n" + "case 1:\n" + "case 2:\n" + " doSomething();\n" + " break;\n" + "default:\n" + " ++variable;\n" + "}", + Style); + + // Wrap before binary operators. + EXPECT_EQ( + "void f()\n" + "{\n" + " if (aaaaaaaaaaaaaaaa\n" + " && bbbbbbbbbbbbbbbbbbbbbbbb\n" + " && (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n" + " return;\n" + "}", + format( + "void f() {\n" + "if (aaaaaaaaaaaaaaaa\n" + "&& bbbbbbbbbbbbbbbbbbbbbbbb\n" + "&& (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n" + "return;\n" + "}", + Style)); + + // Constructor initializers are formatted one per line with the "," on the + // new line. + // FIXME: This needs to be implemented. + // verifyFormat("Constructor()\n" + // " : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" + // " , aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + // " aaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" + // " , aaaaaaaaaaaaaaaaaaaaaaa() {}", + // Style); + + // Do not align comments. + // FIXME: Implement option to suppress comment alignment. + // verifyFormat("int a; // Do not\n" + // "double b; // align comments."); + + // Accept input's line breaks. + EXPECT_EQ("if (aaaaaaaaaaaaaaa\n" + " || bbbbbbbbbbbbbbb) {\n" + " i++;\n" + "}", + format("if (aaaaaaaaaaaaaaa\n" + "|| bbbbbbbbbbbbbbb) { i++; }", + Style)); + EXPECT_EQ("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) {\n" + " i++;\n" + "}", + format("if (aaaaaaaaaaaaaaa || bbbbbbbbbbbbbbb) { i++; }", Style)); +} + #endif } // end namespace tooling |