diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-10-30 14:41:34 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-10-30 14:41:34 +0000 |
commit | f822d3299b46ebefc293d06360e47a6bd731b4bd (patch) | |
tree | 9311b1db2ee882c6472e8f2d6260e7f2080423bf /unittests | |
parent | 5aa4dd9f9d3038556d897395f07c1ea40ab7a28b (diff) |
[clang-format] Handle CRLF correctly when formatting escaped newlines
Subscribers: klimek
Differential Revision: https://reviews.llvm.org/D39420
Contributed by @peterbudai!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316910 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3651fa539d..82530c0376 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2629,14 +2629,39 @@ TEST_F(FormatTest, FormatUnbalancedStructuralElements) { } TEST_F(FormatTest, EscapedNewlines) { - EXPECT_EQ( - "#define A \\\n int i; \\\n int j;", - format("#define A \\\nint i;\\\n int j;", getLLVMStyleWithColumns(11))); + FormatStyle Narrow = getLLVMStyleWithColumns(11); + EXPECT_EQ("#define A \\\n int i; \\\n int j;", + format("#define A \\\nint i;\\\n int j;", Narrow)); EXPECT_EQ("#define A\n\nint i;", format("#define A \\\n\n int i;")); EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();")); EXPECT_EQ("/* \\ \\ \\\n */", format("\\\n/* \\ \\ \\\n */")); EXPECT_EQ("<a\n\\\\\n>", format("<a\n\\\\\n>")); + FormatStyle AlignLeft = getLLVMStyle(); + AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left; + EXPECT_EQ("#define MACRO(x) \\\n" + "private: \\\n" + " int x(int a);\n", + format("#define MACRO(x) \\\n" + "private: \\\n" + " int x(int a);\n", + AlignLeft)); + + // CRLF line endings + EXPECT_EQ("#define A \\\r\n int i; \\\r\n int j;", + format("#define A \\\r\nint i;\\\r\n int j;", Narrow)); + EXPECT_EQ("#define A\r\n\r\nint i;", format("#define A \\\r\n\r\n int i;")); + EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();")); + EXPECT_EQ("/* \\ \\ \\\r\n */", format("\\\r\n/* \\ \\ \\\r\n */")); + EXPECT_EQ("<a\r\n\\\\\r\n>", format("<a\r\n\\\\\r\n>")); + EXPECT_EQ("#define MACRO(x) \\\r\n" + "private: \\\r\n" + " int x(int a);\r\n", + format("#define MACRO(x) \\\r\n" + "private: \\\r\n" + " int x(int a);\r\n", + AlignLeft)); + FormatStyle DontAlign = getLLVMStyle(); DontAlign.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign; DontAlign.MaxEmptyLinesToKeep = 3; @@ -2659,7 +2684,8 @@ TEST_F(FormatTest, EscapedNewlines) { "\\\n" " public: \\\n" " void baz(); \\\n" - " };", DontAlign)); + " };", + DontAlign)); } TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) { |