From: Daniel Jasper Date: Sat, 9 Jan 2016 21:12:45 +0000 (+0000) Subject: clang-format: Fix the counting of leading whitespace in tok::unknown tokens X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca8512adf86996f2080831941418e0c01068dd00;p=clang clang-format: Fix the counting of leading whitespace in tok::unknown tokens Previously, all whitespace characters would increase the starting column, which doesn't make sense. This fixes a problem, e.g. with the length calculation in JS template strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 2ea3b07a29..2689368da5 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1239,6 +1239,8 @@ private: FormatTok->Type = TT_ImplicitStringLiteral; break; } + if (FormatTok->Type == TT_ImplicitStringLiteral) + break; } if (FormatTok->is(TT_ImplicitStringLiteral)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index a35a86ea4e..4e974d7285 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -956,6 +956,9 @@ TEST_F(FormatTestJS, TemplateStrings) { "var y;"); verifyFormat("var x = `\"`; // comment with matching quote \"\n" "var y;"); + EXPECT_EQ("it(`'aaaaaaaaaaaaaaa `, aaaaaaaaa);", + format("it(`'aaaaaaaaaaaaaaa `, aaaaaaaaa) ;", + getGoogleJSStyleWithColumns(40))); // Backticks in a comment - not a template string. EXPECT_EQ("var x = 1 // `/*a`;\n" " ;",