diff options
Diffstat (limited to 'clang/unittests/Format')
| -rw-r--r-- | clang/unittests/Format/ConfigParseTest.cpp | 11 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 60 |
2 files changed, 66 insertions, 5 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 43b2117..d578fa7 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -589,20 +589,20 @@ TEST(ConfigParseTest, ParsesConfiguration) { CHECK_PARSE("AlignTrailingComments: Leave", AlignTrailingComments, FormatStyle::TrailingCommentsAlignmentStyle( - {FormatStyle::TCAS_Leave, 0})); + {FormatStyle::TCAS_Leave, 0, true})); CHECK_PARSE("AlignTrailingComments: Always", AlignTrailingComments, FormatStyle::TrailingCommentsAlignmentStyle( - {FormatStyle::TCAS_Always, 0})); + {FormatStyle::TCAS_Always, 0, true})); CHECK_PARSE("AlignTrailingComments: Never", AlignTrailingComments, FormatStyle::TrailingCommentsAlignmentStyle( - {FormatStyle::TCAS_Never, 0})); + {FormatStyle::TCAS_Never, 0, true})); // For backwards compatibility CHECK_PARSE("AlignTrailingComments: true", AlignTrailingComments, FormatStyle::TrailingCommentsAlignmentStyle( - {FormatStyle::TCAS_Always, 0})); + {FormatStyle::TCAS_Always, 0, true})); CHECK_PARSE("AlignTrailingComments: false", AlignTrailingComments, FormatStyle::TrailingCommentsAlignmentStyle( - {FormatStyle::TCAS_Never, 0})); + {FormatStyle::TCAS_Never, 0, true})); CHECK_PARSE_NESTED_VALUE("Kind: Always", AlignTrailingComments, Kind, FormatStyle::TCAS_Always); CHECK_PARSE_NESTED_VALUE("Kind: Never", AlignTrailingComments, Kind, @@ -611,6 +611,7 @@ TEST(ConfigParseTest, ParsesConfiguration) { FormatStyle::TCAS_Leave); CHECK_PARSE_NESTED_VALUE("OverEmptyLines: 1234", AlignTrailingComments, OverEmptyLines, 1234u); + CHECK_PARSE_NESTED_BOOL(AlignTrailingComments, AlignPPAndNotPP); Style.UseTab = FormatStyle::UT_ForIndentation; CHECK_PARSE("UseTab: Never", UseTab, FormatStyle::UT_Never); diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index d7b2257..684d301 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -3378,6 +3378,66 @@ TEST_F(FormatTestComments, DontAlignOverScope) { "int foobar; // group"); } +TEST_F(FormatTestComments, DontAlignOverPPDirective) { + auto Style = getLLVMStyle(); + Style.AlignTrailingComments.AlignPPAndNotPP = false; + + verifyFormat("int i; // Aligned\n" + "int long; // with this\n" + "#define FOO // only aligned\n" + "#define LOOONG // with other pp directives\n" + "int loooong; // new alignment", + "int i;//Aligned\n" + "int long;//with this\n" + "#define FOO //only aligned\n" + "#define LOOONG //with other pp directives\n" + "int loooong; //new alignment", + Style); + + verifyFormat("#define A // Comment\n" + "#define AB // Comment", + Style); + + Style.ColumnLimit = 30; + verifyNoChange("#define A // Comment\n" + " // Continued\n" + "int i = 0; // New Stuff\n" + " // Continued\n" + "#define Func(X) \\\n" + " X(); \\\n" + " X(); // Comment\n" + " // Continued\n" + "long loong = 1; // Dont align", + Style); + + verifyFormat("#define A // Comment that\n" + " // would wrap\n" + "#define FOO // For the\n" + " // alignment\n" + "#define B // Also\n" + " // aligned", + "#define A // Comment that would wrap\n" + "#define FOO // For the alignment\n" + "#define B // Also\n" + " // aligned", + Style); + + Style.AlignTrailingComments.OverEmptyLines = 1; + verifyNoChange("#define A // Comment\n" + "\n" + " // Continued\n" + "int i = 0; // New Stuff\n" + "\n" + " // Continued\n" + "#define Func(X) \\\n" + " X(); \\\n" + " X(); // Comment\n" + "\n" + " // Continued\n" + "long loong = 1; // Dont align", + Style); +} + TEST_F(FormatTestComments, AlignsBlockCommentDecorations) { verifyFormat("/*\n" " */", |
