diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-30 09:46:12 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-30 09:46:12 +0000 |
commit | 7b038a23819c391d0ba649db8755d3da5cda9ec2 (patch) | |
tree | 371db27d782a5e14d09dccccbf4226bc193a4a39 /clang/unittests/Format/FormatTest.cpp | |
parent | 5fbfafcd8c25f40508687d367182c73d633e6b89 (diff) | |
download | bcm5719-llvm-7b038a23819c391d0ba649db8755d3da5cda9ec2.tar.gz bcm5719-llvm-7b038a23819c391d0ba649db8755d3da5cda9ec2.zip |
Don't generate no-op replacements.
No functional changes.
llvm-svn: 173916
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 32b2ff7f750..97358982cf6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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. //===----------------------------------------------------------------------===// |