Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,53 @@
//===- clang-apply-replacements/ApplyReplacementsTest.cpp
//----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
#include "gtest/gtest.h"
using namespace clang::replace;
using namespace llvm;
namespace clang {
namespace tooling {
static TUDiagnostics
makeTUDiagnostics(const std::string &MainSourceFile, StringRef DiagnosticName,
const DiagnosticMessage &Message,
const StringMap<Replacements> &Replacements,
StringRef BuildDirectory) {
TUDiagnostics TUs;
TUs.push_back({MainSourceFile,
{{DiagnosticName,
Message,
Replacements,
{},
Diagnostic::Warning,
BuildDirectory}}});
return TUs;
}
// Test to ensure diagnostics with no fixes, will be merged correctly
// before applying.
TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
FileManager Files((FileSystemOptions()));
SourceManager SM(Diagnostics, Files);
TUDiagnostics TUs =
makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
FileToReplacementsMap ReplacementsMap;
EXPECT_TRUE(mergeAndDeduplicate(TUs, ReplacementsMap, SM));
EXPECT_TRUE(ReplacementsMap.empty());
}
} // end namespace tooling
} // end namespace clang

View File

@ -0,0 +1,20 @@
get_filename_component(ClangApplyReplacementsLocation
"${CMAKE_CURRENT_SOURCE_DIR}/../../clang-apply-replacements/include" REALPATH)
get_filename_component(CommonIncLocation
"${CMAKE_CURRENT_SOURCE_DIR}/../include" REALPATH)
include_directories(
${ClangApplyReplacementsLocation}
${CommonIncLocation}
)
add_extra_unittest(ClangApplyReplacementsTests
ApplyReplacementsTest.cpp
ReformattingTest.cpp
)
target_link_libraries(ClangApplyReplacementsTests
PRIVATE
clangApplyReplacements
clangBasic
clangToolingCore
)

View File

@ -0,0 +1,67 @@
//===- clang-apply-replacements/ReformattingTest.cpp ----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
#include "common/VirtualFileHelper.h"
#include "clang/Format/Format.h"
#include "clang/Tooling/Refactoring.h"
#include "gtest/gtest.h"
using namespace clang;
using namespace clang::tooling;
using namespace clang::replace;
typedef std::vector<clang::tooling::Replacement> ReplacementsVec;
static Replacement makeReplacement(unsigned Offset, unsigned Length,
unsigned ReplacementLength,
llvm::StringRef FilePath = "") {
return Replacement(FilePath, Offset, Length,
std::string(ReplacementLength, '~'));
}
// generate a set of replacements containing one element
static ReplacementsVec makeReplacements(unsigned Offset, unsigned Length,
unsigned ReplacementLength,
llvm::StringRef FilePath = "~") {
ReplacementsVec Replaces;
Replaces.push_back(
makeReplacement(Offset, Length, ReplacementLength, FilePath));
return Replaces;
}
// Put these functions in the clang::tooling namespace so arg-dependent name
// lookup finds these functions for the EXPECT_EQ macros below.
namespace clang {
namespace tooling {
std::ostream &operator<<(std::ostream &os, const Range &R) {
return os << "Range(" << R.getOffset() << ", " << R.getLength() << ")";
}
} // namespace tooling
} // namespace clang
// Ensure zero-length ranges are produced. Even lines where things are deleted
// need reformatting.
TEST(CalculateChangedRangesTest, producesZeroLengthRange) {
RangeVector Changes = calculateChangedRanges(makeReplacements(0, 4, 0));
EXPECT_EQ(Range(0, 0), Changes.front());
}
// Basic test to ensure replacements turn into ranges properly.
TEST(CalculateChangedRangesTest, calculatesRanges) {
ReplacementsVec R;
R.push_back(makeReplacement(2, 0, 3));
R.push_back(makeReplacement(5, 2, 4));
RangeVector Changes = calculateChangedRanges(R);
Range ExpectedRanges[] = { Range(2, 3), Range(8, 4) };
EXPECT_TRUE(std::equal(Changes.begin(), Changes.end(), ExpectedRanges));
}