diff options
Diffstat (limited to 'clang-tools-extra/clangd/unittests/TweakTesting.cpp')
-rw-r--r-- | clang-tools-extra/clangd/unittests/TweakTesting.cpp | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/clang-tools-extra/clangd/unittests/TweakTesting.cpp b/clang-tools-extra/clangd/unittests/TweakTesting.cpp index e5b619639a5..63ecd7b4d4d 100644 --- a/clang-tools-extra/clangd/unittests/TweakTesting.cpp +++ b/clang-tools-extra/clangd/unittests/TweakTesting.cpp @@ -10,13 +10,9 @@ #include "Annotations.h" #include "SourceCode.h" -#include "TestFS.h" #include "refactor/Tweak.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Error.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include <string> namespace clang { namespace clangd { @@ -63,7 +59,7 @@ std::pair<unsigned, unsigned> rangeOrPoint(const Annotations &A) { cantFail(positionToOffset(A.code(), SelectionRng.end))}; } -MATCHER_P5(TweakIsAvailable, TweakID, Ctx, Header, ExtraFiles, Index, +MATCHER_P3(TweakIsAvailable, TweakID, Ctx, Header, (TweakID + (negation ? " is unavailable" : " is available")).str()) { std::string WrappedCode = wrap(Ctx, arg); Annotations Input(WrappedCode); @@ -71,9 +67,8 @@ MATCHER_P5(TweakIsAvailable, TweakID, Ctx, Header, ExtraFiles, Index, TestTU TU; TU.HeaderCode = Header; TU.Code = Input.code(); - TU.AdditionalFiles = std::move(ExtraFiles); ParsedAST AST = TU.build(); - Tweak::Selection S(Index, AST, Selection.first, Selection.second); + Tweak::Selection S(AST, Selection.first, Selection.second); auto PrepareResult = prepareTweak(TweakID, S); if (PrepareResult) return true; @@ -83,19 +78,17 @@ MATCHER_P5(TweakIsAvailable, TweakID, Ctx, Header, ExtraFiles, Index, } // namespace -std::string TweakTest::apply(llvm::StringRef MarkedCode, - llvm::StringMap<std::string> *EditedFiles) const { +std::string TweakTest::apply(llvm::StringRef MarkedCode) const { std::string WrappedCode = wrap(Context, MarkedCode); Annotations Input(WrappedCode); auto Selection = rangeOrPoint(Input); TestTU TU; TU.HeaderCode = Header; - TU.AdditionalFiles = std::move(ExtraFiles); TU.Code = Input.code(); TU.ExtraArgs = ExtraArgs; ParsedAST AST = TU.build(); - Tweak::Selection S(Index.get(), AST, Selection.first, Selection.second); + Tweak::Selection S(AST, Selection.first, Selection.second); auto T = prepareTweak(TweakID, S); if (!T) { @@ -109,29 +102,18 @@ std::string TweakTest::apply(llvm::StringRef MarkedCode, return "message:\n" + *Result->ShowMessage; if (Result->ApplyEdits.empty()) return "no effect"; - - std::string EditedMainFile; - for (auto &It : Result->ApplyEdits) { - auto NewText = It.second.apply(); - if (!NewText) - return "bad edits: " + llvm::toString(NewText.takeError()); - llvm::StringRef Unwrapped = unwrap(Context, *NewText); - if (It.first() == testPath(TU.Filename)) - EditedMainFile = Unwrapped; - else { - if (!EditedFiles) - ADD_FAILURE() << "There were changes to additional files, but client " - "provided a nullptr for EditedFiles."; - else - EditedFiles->try_emplace(It.first(), Unwrapped.str()); - } - } - return EditedMainFile; + if (Result->ApplyEdits.size() > 1) + return "received multi-file edits"; + + auto ApplyEdit = Result->ApplyEdits.begin()->second; + if (auto NewText = ApplyEdit.apply()) + return unwrap(Context, *NewText); + else + return "bad edits: " + llvm::toString(NewText.takeError()); } ::testing::Matcher<llvm::StringRef> TweakTest::isAvailable() const { - return TweakIsAvailable(llvm::StringRef(TweakID), Context, Header, ExtraFiles, - Index.get()); + return TweakIsAvailable(llvm::StringRef(TweakID), Context, Header); } std::vector<std::string> TweakTest::expandCases(llvm::StringRef MarkedCode) { |