Eric Liu | 40ef2fb | 2016-08-01 10:16:37 +0000 | [diff] [blame] | 1 | //===- unittest/Tooling/ReplacementTest.h - Replacements related test------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Liu | 40ef2fb | 2016-08-01 10:16:37 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines utility class and function for Replacement related tests. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |
| 14 | #define LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |
| 15 | |
| 16 | #include "RewriterTestContext.h" |
| 17 | #include "clang/Tooling/Core/Replacement.h" |
| 18 | #include "gtest/gtest.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | namespace tooling { |
| 22 | |
| 23 | /// \brief Converts a set of replacements to Replacements class. |
| 24 | /// \return A Replacements class containing \p Replaces on success; otherwise, |
| 25 | /// an empty Replacements is returned. |
Daniel Jasper | 03a04fe | 2016-12-12 12:42:29 +0000 | [diff] [blame] | 26 | inline tooling::Replacements |
Eric Liu | 40ef2fb | 2016-08-01 10:16:37 +0000 | [diff] [blame] | 27 | toReplacements(const std::set<tooling::Replacement> &Replaces) { |
| 28 | tooling::Replacements Result; |
| 29 | for (const auto &R : Replaces) { |
| 30 | auto Err = Result.add(R); |
| 31 | EXPECT_TRUE(!Err); |
| 32 | if (Err) { |
| 33 | llvm::errs() << llvm::toString(std::move(Err)) << "\n"; |
| 34 | return tooling::Replacements(); |
| 35 | } |
| 36 | } |
| 37 | return Result; |
| 38 | } |
| 39 | |
| 40 | /// \brief A utility class for replacement related tests. |
| 41 | class ReplacementTest : public ::testing::Test { |
| 42 | protected: |
| 43 | tooling::Replacement createReplacement(SourceLocation Start, unsigned Length, |
| 44 | llvm::StringRef ReplacementText) { |
| 45 | return tooling::Replacement(Context.Sources, Start, Length, |
| 46 | ReplacementText); |
| 47 | } |
| 48 | |
| 49 | RewriterTestContext Context; |
| 50 | }; |
| 51 | |
| 52 | } // namespace tooling |
| 53 | } // namespace clang |
| 54 | |
| 55 | #endif // LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |