diff options
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0d85789a1ddb..d61dc7f662c2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -516,6 +516,10 @@ TEST_F(FormatTest, FormatsForLoop) { " aaaaaaaaaa);\n" " iter; ++iter) {\n" "}"); + verifyFormat("for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbbbbbbb;\n" + " ++aaaaaaaaaaaaaaaaaaaaaaaaaaa) {"); FormatStyle NoBinPacking = getLLVMStyle(); NoBinPacking.BinPackParameters = false; @@ -3216,6 +3220,24 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) { verifyFormat("enum E {}"); } +TEST_F(FormatTest, FormatBeginBlockEndMacros) { + FormatStyle Style = getLLVMStyle(); + Style.MacroBlockBegin = "^[A-Z_]+_BEGIN$"; + Style.MacroBlockEnd = "^[A-Z_]+_END$"; + verifyFormat("FOO_BEGIN\n" + " FOO_ENTRY\n" + "FOO_END", Style); + verifyFormat("FOO_BEGIN\n" + " NESTED_FOO_BEGIN\n" + " NESTED_FOO_ENTRY\n" + " NESTED_FOO_END\n" + "FOO_END", Style); + verifyFormat("FOO_BEGIN(Foo, Bar)\n" + " int x;\n" + " x = 1;\n" + "FOO_END(Baz)", Style); +} + //===----------------------------------------------------------------------===// // Line break tests. //===----------------------------------------------------------------------===// @@ -5535,6 +5557,11 @@ TEST_F(FormatTest, UnderstandsAttributes) { verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n" "aaaaaaaaaaaaaaaaaaaaaaa(int i);"); + FormatStyle AfterType = getLLVMStyle(); + AfterType.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All; + verifyFormat("__attribute__((nodebug)) void\n" + "foo() {}\n", + AfterType); } TEST_F(FormatTest, UnderstandsEllipsis) { @@ -8552,6 +8579,50 @@ TEST_F(FormatTest, LinuxBraceBreaking) { LinuxBraceStyle); } +TEST_F(FormatTest, MozillaBraceBreaking) { + FormatStyle MozillaBraceStyle = getLLVMStyle(); + MozillaBraceStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla; + verifyFormat("namespace a {\n" + "class A\n" + "{\n" + " void f()\n" + " {\n" + " if (true) {\n" + " a();\n" + " b();\n" + " }\n" + " }\n" + " void g() { return; }\n" + "};\n" + "enum E\n" + "{\n" + " A,\n" + " // foo\n" + " B,\n" + " C\n" + "};\n" + "struct B\n" + "{\n" + " int x;\n" + "};\n" + "}\n", + MozillaBraceStyle); + verifyFormat("struct S\n" + "{\n" + " int Type;\n" + " union\n" + " {\n" + " int x;\n" + " double y;\n" + " } Value;\n" + " class C\n" + " {\n" + " MyFavoriteType Value;\n" + " } Class;\n" + "}\n", + MozillaBraceStyle); +} + TEST_F(FormatTest, StroustrupBraceBreaking) { FormatStyle StroustrupBraceStyle = getLLVMStyle(); StroustrupBraceStyle.BreakBeforeBraces = FormatStyle::BS_Stroustrup; @@ -9192,6 +9263,8 @@ TEST_F(FormatTest, ParsesConfiguration) { FormatStyle::BS_Attach); CHECK_PARSE("BreakBeforeBraces: Linux", BreakBeforeBraces, FormatStyle::BS_Linux); + CHECK_PARSE("BreakBeforeBraces: Mozilla", BreakBeforeBraces, + FormatStyle::BS_Mozilla); CHECK_PARSE("BreakBeforeBraces: Stroustrup", BreakBeforeBraces, FormatStyle::BS_Stroustrup); CHECK_PARSE("BreakBeforeBraces: Allman", BreakBeforeBraces, @@ -9788,6 +9861,20 @@ TEST_F(FormatTest, FormatsLambdas) { " << std::count_if(v.begin(), v.end(), [](int x) {\n" " return x == 2; // force break\n" " });"); + verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([=](\n" + " int iiiiiiiiiiii) {\n" + " return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa;\n" + "});", + getLLVMStyleWithColumns(60)); + verifyFormat("SomeFunction({[&] {\n" + " // comment\n" + " },\n" + " [&] {\n" + " // comment\n" + " }});"); + verifyFormat("SomeFunction({[&] {\n" + " // comment\n" + "}});"); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n"); |