[clang-format] fix PR38557 - comments between "default" and ':' causes the case label to be treated as an identifier
Summary:
The Bug was reported and fixed by Owen Pan. See the original bug report here: https://bugs.llvm.org/show_bug.cgi?id=38557
Patch by Owen Pan!
Reviewers: krasimir, djasper, klimek
Reviewed By: klimek
Subscribers: JonasToth, cfe-commits
Differential Revision: https://reviews.llvm.org/D50697
llvm-svn: 340624
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d73b1d8..a603012 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1145,6 +1145,22 @@
" break;\n"
"}",
Style);
+ Style.ColumnLimit = 80;
+ Style.AllowShortCaseLabelsOnASingleLine = false;
+ Style.IndentCaseLabels = true;
+ EXPECT_EQ("switch (n) {\n"
+ " default /*comments*/:\n"
+ " return true;\n"
+ " case 0:\n"
+ " return false;\n"
+ "}",
+ format("switch (n) {\n"
+ "default/*comments*/:\n"
+ " return true;\n"
+ "case 0:\n"
+ " return false;\n"
+ "}",
+ Style));
}
TEST_F(FormatTest, FormatsLabels) {