diff options
Diffstat (limited to 'clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp')
-rw-r--r-- | clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp index b5f09f9..02133ec 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp @@ -15,6 +15,8 @@ namespace clang { namespace clangd { namespace { +using ::testing::UnorderedElementsAre; + TWEAK_TEST(DefineOutline); TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) { @@ -747,6 +749,43 @@ TEST_F(DefineOutlineTest, FailsMacroSpecifier) { } } +TWEAK_WORKSPACE_TEST(DefineOutline); + +// Test that DefineOutline's use of getCorrespondingHeaderOrSource() +// to find the source file corresponding to a header file in which the +// tweak is invoked is working as intended. +TEST_F(DefineOutlineWorkspaceTest, FindsCorrespondingSource) { + llvm::Annotations HeaderBefore(R"cpp( +class A { + void bar(); + void f^oo(){} +}; +)cpp"); + std::string SourceBefore(R"cpp( +#include "a.hpp" +void A::bar(){} +)cpp"); + std::string HeaderAfter = R"cpp( +class A { + void bar(); + void foo(); +}; +)cpp"; + std::string SourceAfter = R"cpp( +#include "a.hpp" +void A::bar(){} +void A::foo(){} +)cpp"; + Workspace.addSource("a.hpp", HeaderBefore.code()); + Workspace.addMainFile("a.cpp", SourceBefore); + auto Result = apply("a.hpp", {HeaderBefore.point(), HeaderBefore.point()}); + EXPECT_THAT(Result, + AllOf(withStatus("success"), + editedFiles(UnorderedElementsAre( + FileWithContents(testPath("a.hpp"), HeaderAfter), + FileWithContents(testPath("a.cpp"), SourceAfter))))); +} + } // namespace } // namespace clangd } // namespace clang |