From f67c32466d782824c67a3f31196eb31d22faa7fa Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 1 Nov 2015 00:27:35 +0000 Subject: 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 --- clang/unittests/Format/FormatTestSelective.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/unittests/Format/FormatTestSelective.cpp') 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 -- cgit v1.2.3