summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2017-05-08 15:08:00 +0000
committerDaniel Jasper <djasper@google.com>2017-05-08 15:08:00 +0000
commit6878143d92cd036e9916ff853b8bc522e6e118b7 (patch)
treee6ba82b01f5387b6c15dcdb79ba4445e89eb9054 /unittests
parentc7b6c9527a4ed79fee5bba10a0afb2215a9cbb27 (diff)
[clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding
DontAlign This converts the clang-format option AlignEscapedNewlinesLeft from a boolean to an enum, named AlignEscapedNewlines, with options Left (prev. true), Right (prev. false), and a new option DontAlign. When set to DontAlign, the backslashes are placed just after the last token in each line: #define EXAMPLE \ do { \ int x = aaaaa; \ int b; \ int dddddddddd; \ } while (0) Patch by jtbandes. Thank you! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp42
-rw-r--r--unittests/Format/FormatTestSelective.cpp4
2 files changed, 36 insertions, 10 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 34faa17b1c..cec25440a5 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -342,7 +342,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
verifyFormat("if (a)\n if (b) {\n f();\n }\ng();");
FormatStyle AllowsMergedIf = getLLVMStyle();
- AllowsMergedIf.AlignEscapedNewlinesLeft = true;
+ AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
verifyFormat("if (a)\n"
" // comment\n"
@@ -6477,7 +6477,7 @@ TEST_F(FormatTest, BreaksStringLiterals) {
EXPECT_EQ("\"some text other\";", format("\"some text other\";", Style));
FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
- AlignLeft.AlignEscapedNewlinesLeft = true;
+ AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left;
EXPECT_EQ("#define A \\\n"
" \"some \" \\\n"
" \"text \" \\\n"
@@ -6878,7 +6878,7 @@ TEST_F(FormatTest, ConfigurableUseOfTab) {
FormatStyle Tab = getLLVMStyleWithColumns(42);
Tab.IndentWidth = 8;
Tab.UseTab = FormatStyle::UT_Always;
- Tab.AlignEscapedNewlinesLeft = true;
+ Tab.AlignEscapedNewlines = FormatStyle::ENAS_Left;
EXPECT_EQ("if (aaaaaaaa && // q\n"
" bb)\t\t// w\n"
@@ -7659,14 +7659,21 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
"int oneTwoThree = 123;\n"
"int oneTwo = 12;",
Alignment));
- Alignment.AlignEscapedNewlinesLeft = true;
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+ verifyFormat("#define A \\\n"
+ " int aaaa = 12; \\\n"
+ " int b = 23; \\\n"
+ " int ccc = 234; \\\n"
+ " int dddddddddd = 2345;",
+ Alignment);
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
verifyFormat("#define A \\\n"
" int aaaa = 12; \\\n"
" int b = 23; \\\n"
" int ccc = 234; \\\n"
" int dddddddddd = 2345;",
Alignment);
- Alignment.AlignEscapedNewlinesLeft = false;
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
verifyFormat("#define A "
" \\\n"
" int aaaa = 12; "
@@ -7933,14 +7940,21 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"}",
Alignment));
Alignment.AlignConsecutiveAssignments = false;
- Alignment.AlignEscapedNewlinesLeft = true;
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+ verifyFormat("#define A \\\n"
+ " int aaaa = 12; \\\n"
+ " float b = 23; \\\n"
+ " const int ccc = 234; \\\n"
+ " unsigned dddddddddd = 2345;",
+ Alignment);
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Left;
verifyFormat("#define A \\\n"
" int aaaa = 12; \\\n"
" float b = 23; \\\n"
" const int ccc = 234; \\\n"
" unsigned dddddddddd = 2345;",
Alignment);
- Alignment.AlignEscapedNewlinesLeft = false;
+ Alignment.AlignEscapedNewlines = FormatStyle::ENAS_Right;
Alignment.ColumnLimit = 30;
verifyFormat("#define A \\\n"
" int aaaa = 12; \\\n"
@@ -8725,7 +8739,6 @@ TEST_F(FormatTest, GetsCorrectBasedOnStyle) {
TEST_F(FormatTest, ParsesConfigurationBools) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;
- CHECK_PARSE_BOOL(AlignEscapedNewlinesLeft);
CHECK_PARSE_BOOL(AlignOperands);
CHECK_PARSE_BOOL(AlignTrailingComments);
CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
@@ -8848,6 +8861,19 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("AlignAfterOpenBracket: true", AlignAfterOpenBracket,
FormatStyle::BAS_Align);
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+ CHECK_PARSE("AlignEscapedNewlines: DontAlign", AlignEscapedNewlines,
+ FormatStyle::ENAS_DontAlign);
+ CHECK_PARSE("AlignEscapedNewlines: Left", AlignEscapedNewlines,
+ FormatStyle::ENAS_Left);
+ CHECK_PARSE("AlignEscapedNewlines: Right", AlignEscapedNewlines,
+ FormatStyle::ENAS_Right);
+ // For backward compatibility:
+ CHECK_PARSE("AlignEscapedNewlinesLeft: true", AlignEscapedNewlines,
+ FormatStyle::ENAS_Left);
+ CHECK_PARSE("AlignEscapedNewlinesLeft: false", AlignEscapedNewlines,
+ FormatStyle::ENAS_Right);
+
Style.UseTab = FormatStyle::UT_ForIndentation;
CHECK_PARSE("UseTab: Never", UseTab, FormatStyle::UT_Never);
CHECK_PARSE("UseTab: ForIndentation", UseTab, FormatStyle::UT_ForIndentation);
diff --git a/unittests/Format/FormatTestSelective.cpp b/unittests/Format/FormatTestSelective.cpp
index 8046d7fab2..9ee87b34c2 100644
--- a/unittests/Format/FormatTestSelective.cpp
+++ b/unittests/Format/FormatTestSelective.cpp
@@ -325,7 +325,7 @@ TEST_F(FormatTestSelective, WrongIndent) {
}
TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {
- Style.AlignEscapedNewlinesLeft = true;
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
EXPECT_EQ("int i;\n"
"#define A \\\n"
" int i; \\\n"
@@ -467,7 +467,7 @@ TEST_F(FormatTestSelective, ReformatRegionAdjustsIndent) {
TEST_F(FormatTestSelective, UnderstandsTabs) {
Style.IndentWidth = 8;
Style.UseTab = FormatStyle::UT_Always;
- Style.AlignEscapedNewlinesLeft = true;
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
EXPECT_EQ("void f() {\n"
"\tf();\n"
"\tg();\n"