diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-07-22 20:26:29 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-07-22 20:26:29 +0000 |
commit | 55b0be72d11ce678df24d8971d5553415a0edd61 (patch) | |
tree | e2428cb71cab77800de04fd621c3816df321fc4f /clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp | |
parent | 7d6753738a0a84fd3c2427fda8daf028687ccaee (diff) | |
download | bcm5719-llvm-55b0be72d11ce678df24d8971d5553415a0edd61.tar.gz bcm5719-llvm-55b0be72d11ce678df24d8971d5553415a0edd61.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.
Author: Guillaume Papin <guillaume.papin@epitech.eu>
llvm-svn: 186866
Diffstat (limited to 'clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp')
-rw-r--r-- | clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp | 50 |
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); +} |