Eric Liu | 40ef2fb | 2016-08-01 10:16:37 +0000 | [diff] [blame] | 1 | //===- unittest/Tooling/ReplacementTest.h - Replacements related test------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines utility class and function for Replacement related tests. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |
| 15 | #define LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |
| 16 | |
| 17 | #include "RewriterTestContext.h" |
| 18 | #include "clang/Tooling/Core/Replacement.h" |
| 19 | #include "gtest/gtest.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | namespace tooling { |
| 23 | |
| 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 | static 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); |
| 32 | EXPECT_TRUE(!Err); |
| 33 | if (Err) { |
| 34 | llvm::errs() << llvm::toString(std::move(Err)) << "\n"; |
| 35 | return tooling::Replacements(); |
| 36 | } |
| 37 | } |
| 38 | return Result; |
| 39 | } |
| 40 | |
| 41 | /// \brief A utility class for replacement related tests. |
| 42 | class ReplacementTest : public ::testing::Test { |
| 43 | protected: |
| 44 | tooling::Replacement createReplacement(SourceLocation Start, unsigned Length, |
| 45 | llvm::StringRef ReplacementText) { |
| 46 | return tooling::Replacement(Context.Sources, Start, Length, |
| 47 | ReplacementText); |
| 48 | } |
| 49 | |
| 50 | RewriterTestContext Context; |
| 51 | }; |
| 52 | |
| 53 | } // namespace tooling |
| 54 | } // namespace clang |
| 55 | |
| 56 | #endif // LLVM_CLANG_UNITTESTS_TOOLING_REPLACEMENTTESTBASE_H |