summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2015-05-12 09:23:57 +0000
committerManuel Klimek <klimek@google.com>2015-05-12 09:23:57 +0000
commit3d3ea84a4f8fcdf1f4c17b80c10389b92b6ad502 (patch)
tree119ae2caf435e20d2a0620cee16a02dc6d6d55fc /clang/unittests/Format/FormatTest.cpp
parent108c325d6edca86aec9a86132bb7c657471ab40c (diff)
downloadbcm5719-llvm-3d3ea84a4f8fcdf1f4c17b80c10389b92b6ad502.tar.gz
bcm5719-llvm-3d3ea84a4f8fcdf1f4c17b80c10389b92b6ad502.zip
Refactor clang-format's formatter.
Summary: a) Pull out a class LevelIndentTracker whose responsibility is to keep track of the indent of levels across multiple annotated lines. b) Put all responsibility for merging lines into the LineJoiner; make the LineJoiner iterate over the lines so we never operate on a line that might be merged later; this makes the interface safer to use. c) Move formatting of the end-of-file whitespace into formatFirstToken. Fix bugs that became obvious after the refactoring: 1. We would not format lines with offsets correctly inside nested blocks if only the outer expression was affected: int x = s({ // clang-format only this line class X { public: // ^ this starts at the non-modified indnent level; previously we would // not fix this, now we correctly outdent it. void f(); }; }); 2. We would incorrectly align comments across lines that do not have comments for lines with nested blocks: int expression; // with comment int x = s({ int y; // comment int z; // we would incorrectly align this comment with the comment on // 'expression' }); llvm-svn: 237104
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 91540d4f2d6..22217c06f4c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2775,9 +2775,10 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
verifyFormat("#d, = };");
verifyFormat("#if \"a");
verifyIncompleteFormat("({\n"
- "#define b }\\\n"
+ "#define b \\\n"
+ " } \\\n"
" a\n"
- "a");
+ "a", getLLVMStyleWithColumns(15));
verifyFormat("#define A \\\n"
" { \\\n"
" {\n"
@@ -3179,6 +3180,30 @@ TEST_F(FormatTest, LayoutBlockInsideParens) {
" if (a)\n"
" f();\n"
"});");
+ EXPECT_EQ("int longlongname; // comment\n"
+ "int x = f({\n"
+ " int x; // comment\n"
+ " int y; // comment\n"
+ "});",
+ format("int longlongname; // comment\n"
+ "int x = f({\n"
+ " int x; // comment\n"
+ " int y; // comment\n"
+ "});",
+ 65, 0, getLLVMStyle()));
+ EXPECT_EQ("int s = f({\n"
+ " class X {\n"
+ " public:\n"
+ " void f();\n"
+ " };\n"
+ "});",
+ format("int s = f({\n"
+ " class X {\n"
+ " public:\n"
+ " void f();\n"
+ " };\n"
+ "});",
+ 0, 0, getLLVMStyle()));
}
TEST_F(FormatTest, LayoutBlockInsideStatement) {
OpenPOWER on IntegriCloud