aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 32b2ff7f75..97358982cf 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -38,6 +38,7 @@ protected:
tooling::Replacements Replace = reformat(Style, Lex, Context.Sources,
Ranges,
new IgnoringDiagConsumer());
+ ReplacementCount = Replace.size();
EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite));
DEBUG(llvm::errs() << "\n" << Context.getRewrittenText(ID) << "\n\n");
return Context.getRewrittenText(ID);
@@ -105,6 +106,8 @@ protected:
verifyFormat(text);
verifyFormat(llvm::Twine("void f() { " + text + " }").str());
}
+
+ int ReplacementCount;
};
TEST_F(FormatTest, MessUp) {
@@ -148,6 +151,19 @@ TEST_F(FormatTest, ImportantSpaces) {
verifyFormat("vector< ::Type> v;");
}
+TEST_F(FormatTest, OnlyGeneratesNecessaryReplacements) {
+ EXPECT_EQ("if (a) {\n"
+ " f();\n"
+ "}", format("if(a){f();}"));
+ EXPECT_EQ(4, ReplacementCount);
+ EXPECT_EQ("if (a) {\n"
+ " f();\n"
+ "}", format("if (a) {\n"
+ " f();\n"
+ "}"));
+ EXPECT_EQ(0, ReplacementCount);
+}
+
//===----------------------------------------------------------------------===//
// Tests for control statements.
//===----------------------------------------------------------------------===//