diff options
author | Daniel Jasper <djasper@google.com> | 2014-09-10 13:11:45 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-09-10 13:11:45 +0000 |
commit | b87899b567b95fa695c943e2d9b760966d38c2c9 (patch) | |
tree | c7ed5ec9b23f0ef91500de23e998f85bf8f5bd5c /clang/unittests/Format/FormatTest.cpp | |
parent | e7b92f0e8109877b073ff28c61c79ebbada07565 (diff) | |
download | bcm5719-llvm-b87899b567b95fa695c943e2d9b760966d38c2c9.tar.gz bcm5719-llvm-b87899b567b95fa695c943e2d9b760966d38c2c9.zip |
clang-format: Add option to allow short case labels on a single line.
On a single line:
switch (a) {
case 1: x = 1; return;
case 2: x = 2; return;
default: break;
}
Not on a single line:
switch (a) {
case 1:
x = 1;
return;
case 2:
x = 2;
return;
default:
break;
}
This partly addresses llvm.org/PR16535. In the long run, we probably want to
lay these out in columns.
llvm-svn: 217501
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6f00acf38f3..8b8aaf1b4a6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -700,6 +700,47 @@ TEST_F(FormatTest, CaseRanges) { "}"); } +TEST_F(FormatTest, ShortCaseLabels) { + FormatStyle Style = getLLVMStyle(); + Style.AllowShortCaseLabelsOnASingleLine = true; + verifyFormat("switch (a) {\n" + "case 1: x = 1; break;\n" + "case 2: return;\n" + "case 3:\n" + "case 4:\n" + "case 5: return;\n" + "default: y = 1; break;\n" + "}", + Style); + verifyFormat("switch (a) {\n" + "case 1: {\n" + "}\n" + "case 2: {\n" + " return;\n" + "}\n" + "case 3: {\n" + " x = 1;\n" + " return;\n" + "}\n" + "case 4:\n" + " if (x)\n" + " return;\n" + "}", + Style); + Style.ColumnLimit = 21; + verifyFormat("switch (a) {\n" + "case 1: x = 1; break;\n" + "case 2: return;\n" + "case 3:\n" + "case 4:\n" + "case 5: return;\n" + "default:\n" + " y = 1;\n" + " break;\n" + "}", + Style); +} + TEST_F(FormatTest, FormatsLabels) { verifyFormat("void f() {\n" " some_code();\n" @@ -8316,6 +8357,7 @@ TEST_F(FormatTest, ParsesConfigurationBools) { CHECK_PARSE_BOOL(AlignTrailingComments); CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine); CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine); + CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine); CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine); CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine); CHECK_PARSE_BOOL(AlwaysBreakAfterDefinitionReturnType); |