summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-07-23 12:50:03 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-07-23 12:50:03 +0000
commit571a64159b4c828f2748b228993619bee416b90b (patch)
treef756baf58c396121d0cf4168057d08f623fa94f4 /clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
parent2dfb1cfd0cfffcf6444740579f39a865107a34e3 (diff)
downloadbcm5719-llvm-571a64159b4c828f2748b228993619bee416b90b.tar.gz
bcm5719-llvm-571a64159b4c828f2748b228993619bee416b90b.zip
cp11-migrate: Integration with LibFormat
Adding a feature to optionally reformat code changed by the migrator. Like LibFormat, can choose between built-in styles (LLVM, Mozilla, Google, Chromium) or use a YAML-format config file. Now with no dependency on iostream by the Reformatting.cpp LIT test. Author: Guillaume Papin <guillaume.papin@epitech.eu> llvm-svn: 186938
Diffstat (limited to 'clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp')
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
new file mode 100644
index 00000000000..fcde6b81db4
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
@@ -0,0 +1,50 @@
+//===- cpp11-migrate/ReformattingTest.cpp - Reformatting unit tests -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Core/Reformatting.h"
+#include "Core/FileOverrides.h"
+#include "gtest/gtest.h"
+#include "VirtualFileHelper.h"
+
+using namespace clang;
+using namespace clang::tooling;
+
+namespace {
+// convenience function to create a ChangedRanges containing one Range
+ChangedRanges makeChangedRanges(unsigned Offset, unsigned Length) {
+ ChangedRanges Changes;
+ Replacements Replaces;
+
+ Replaces.insert(Replacement("", Offset, 0, std::string(Length, '~')));
+ Changes.adjustChangedRanges(Replaces);
+ return Changes;
+}
+} // end anonymous namespace
+
+TEST(Reformatter, SingleReformat) {
+ VirtualFileHelper VFHelper;
+ llvm::StringRef FileName = "<test>";
+ VFHelper.mapFile(FileName, "int a;\n"
+ "int b;\n");
+
+ Reformatter ChangesReformatter(format::getLLVMStyle());
+ ChangedRanges Changes = makeChangedRanges(0, 6);
+ tooling::Replacements Replaces = ChangesReformatter.reformatSingleFile(
+ FileName, Changes, VFHelper.getNewSourceManager());
+
+ SourceOverrides Overrides(FileName, /*TrackChanges=*/false);
+ Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager());
+
+ std::string Expected, Result;
+
+ Expected = "int a;\n"
+ "int b;\n";
+ Result = Overrides.getMainFileContent();
+ EXPECT_EQ(Expected, Result);
+}
OpenPOWER on IntegriCloud