summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-16 10:40:07 +0000
committerDaniel Jasper <djasper@google.com>2013-05-16 10:40:07 +0000
commitec04c0dba0b2ca2ad6906009e8eca54928b99c46 (patch)
tree90b56b68a2c79a436457b6cdf858c147c17b732f /clang/unittests/Format/FormatTest.cpp
parentf9eb9b18830349057d4608ecbac2077e84906f5c (diff)
downloadbcm5719-llvm-ec04c0dba0b2ca2ad6906009e8eca54928b99c46.tar.gz
bcm5719-llvm-ec04c0dba0b2ca2ad6906009e8eca54928b99c46.zip
Add a more convenient interface to use clang-format.
It turns out that several implementations go through the trouble of setting up a SourceManager and Lexer and abstracting this into a function makes usage easier. Also abstracts SourceManager-independent ranges out of tooling::Refactoring and provides a convenience function to create them from line ranges. llvm-svn: 181997
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8ee0245d1db..76ec61385dd 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10,7 +10,6 @@
#define DEBUG_TYPE "format-test"
#include "clang/Format/Format.h"
-#include "../Tooling/RewriterTestContext.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/Debug.h"
#include "gtest/gtest.h"
@@ -23,21 +22,13 @@ protected:
std::string format(llvm::StringRef Code, unsigned Offset, unsigned Length,
const FormatStyle &Style) {
DEBUG(llvm::errs() << "---\n");
- RewriterTestContext Context;
- FileID ID = Context.createInMemoryFile("input.cc", Code);
- SourceLocation Start =
- Context.Sources.getLocForStartOfFile(ID).getLocWithOffset(Offset);
- std::vector<CharSourceRange> Ranges(
- 1,
- CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
- Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources,
- getFormattingLangOpts());
- tooling::Replacements Replace =
- reformat(Style, Lex, Context.Sources, Ranges);
- ReplacementCount = Replace.size();
- EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite));
- DEBUG(llvm::errs() << "\n" << Context.getRewrittenText(ID) << "\n\n");
- return Context.getRewrittenText(ID);
+ std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
+ tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+ ReplacementCount = Replaces.size();
+ std::string Result = applyAllReplacements(Code, Replaces);
+ EXPECT_NE("", Result);
+ DEBUG(llvm::errs() << "\n" << Result << "\n\n");
+ return Result;
}
std::string
OpenPOWER on IntegriCloud