summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-11-01 00:27:35 +0000
committerDaniel Jasper <djasper@google.com>2015-11-01 00:27:35 +0000
commitf67c32466d782824c67a3f31196eb31d22faa7fa (patch)
treef75ff2d76d478140aa2a1e8c4ba7bfdda4e0a7b2 /clang/unittests/Format
parent2f5e8874f3a973eb9aec8fd92e7f1cbbc7c00494 (diff)
downloadbcm5719-llvm-f67c32466d782824c67a3f31196eb31d22faa7fa.tar.gz
bcm5719-llvm-f67c32466d782824c67a3f31196eb31d22faa7fa.zip
clang-format: Be slightly more cautious when formatting subsequent lines after a change. With r251474, clang-format could indent the entire rest of the file, if there is a missing closing brace, e.g. while writing code in an editor.
Summary: With this change, clang-format stops formatting when either it leaves the current scope or when it comes back to the initial scope after going into a nested one. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D14213 llvm-svn: 251760
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTestSelective.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp
index a28dfd32e1c..9c4d1c3d2b0 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -446,6 +446,27 @@ TEST_F(FormatTestSelective, UnderstandsTabs) {
21, 0));
}
+TEST_F(FormatTestSelective, StopFormattingWhenLeavingScope) {
+ EXPECT_EQ(
+ "void f() {\n"
+ " if (a) {\n"
+ " g();\n"
+ " h();\n"
+ "}\n"
+ "\n"
+ "void g() {\n"
+ "}",
+ format("void f() {\n"
+ " if (a) {\n" // Assume this was added without the closing brace.
+ " g();\n"
+ " h();\n"
+ "}\n"
+ "\n"
+ "void g() {\n" // Make sure not to format this.
+ "}",
+ 15, 0));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
OpenPOWER on IntegriCloud