1 //===- unittest/Tooling/ReplacementTest.h - Replacements related test------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines utility class and function for Replacement related tests.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H
15 #define LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H
17 #include "RewriterTestContext.h"
18 #include "clang/Tooling/Core/Replacement.h"
19 #include "gtest/gtest.h"
24 /// \brief Converts a set of replacements to Replacements class.
25 /// \return A Replacements class containing \p Replaces on success; otherwise,
26 /// an empty Replacements is returned.
27 inline tooling::Replacements
28 toReplacements(const std::set<tooling::Replacement> &Replaces) {
29 tooling::Replacements Result;
30 for (const auto &R : Replaces) {
31 auto Err = Result.add(R);
34 llvm::errs() << llvm::toString(std::move(Err)) << "\n";
35 return tooling::Replacements();
41 /// \brief A utility class for replacement related tests.
42 class ReplacementTest : public ::testing::Test {
44 tooling::Replacement createReplacement(SourceLocation Start, unsigned Length,
45 llvm::StringRef ReplacementText) {
46 return tooling::Replacement(Context.Sources, Start, Length,
50 RewriterTestContext Context;
53 } // namespace tooling
56 #endif // LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H