comparison clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents
children 5f17cb93ff66
comparison
equal deleted inserted replaced
220:42394fc6a535 221:79ff65ed7e25
1 //===--- FeatureModulesTests.cpp -------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "FeatureModule.h"
10 #include "Selection.h"
11 #include "TestTU.h"
12 #include "refactor/Tweak.h"
13 #include "support/Logger.h"
14 #include "llvm/Support/Error.h"
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17 #include <memory>
18
19 namespace clang {
20 namespace clangd {
21 namespace {
22
23 TEST(FeatureModulesTest, ContributesTweak) {
24 static constexpr const char *TweakID = "ModuleTweak";
25 struct TweakContributingModule final : public FeatureModule {
26 struct ModuleTweak final : public Tweak {
27 const char *id() const override { return TweakID; }
28 bool prepare(const Selection &Sel) override { return true; }
29 Expected<Effect> apply(const Selection &Sel) override {
30 return error("not implemented");
31 }
32 std::string title() const override { return id(); }
33 llvm::StringLiteral kind() const override {
34 return llvm::StringLiteral("");
35 };
36 };
37
38 void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &Out) override {
39 Out.emplace_back(new ModuleTweak);
40 }
41 };
42
43 FeatureModuleSet Set;
44 Set.add(std::make_unique<TweakContributingModule>());
45
46 auto AST = TestTU::withCode("").build();
47 auto Tree =
48 SelectionTree::createRight(AST.getASTContext(), AST.getTokens(), 0, 0);
49 auto Actual = prepareTweak(
50 TweakID, Tweak::Selection(nullptr, AST, 0, 0, std::move(Tree), nullptr),
51 &Set);
52 ASSERT_TRUE(bool(Actual));
53 EXPECT_EQ(Actual->get()->id(), TweakID);
54 }
55
56 } // namespace
57 } // namespace clangd
58 } // namespace clang