clang-format: Support case ranges.
Before (note the missing space before "..." which can lead to compile
errors):
switch (x) {
case 'A'... 'Z':
case 1... 5:
break;
}
After:
switch (x) {
case 'A' ... 'Z':
case 1 ... 5:
break;
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193050 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 9bc1097..7e794a3 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1237,7 +1237,7 @@
if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
return false;
if (Right.is(tok::ellipsis))
- return false;
+ return Left.Tok.isLiteral();
if (Left.is(tok::l_square) && Right.is(tok::amp))
return false;
if (Right.Type == TT_PointerOrReference)
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index dcb708e..ad1cf75 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -590,6 +590,14 @@
"});");
}
+TEST_F(FormatTest, CaseRanges) {
+ verifyFormat("switch (x) {\n"
+ "case 'A' ... 'Z':\n"
+ "case 1 ... 5:\n"
+ " break;\n"
+ "}");
+}
+
TEST_F(FormatTest, FormatsLabels) {
verifyFormat("void f() {\n"
" some_code();\n"