From: Daniel Jasper Date: Sun, 20 Oct 2013 16:56:16 +0000 (+0000) Subject: clang-format: Support case ranges. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3c887dcb70220eced72935725cd94d7e8325912;p=clang 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 9bc109787a..7e794a3d2d 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1237,7 +1237,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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 dcb708e0d7..ad1cf75392 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -590,6 +590,14 @@ TEST_F(FormatTest, FormatsSwitchStatement) { "});"); } +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"