diff --git a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp index d466dd5349d4..f3a479a9a240 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp @@ -8,11 +8,12 @@ #include "Config.h" #include "TweakTesting.h" +#include "support/Context.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" #include +#include namespace clang { namespace clangd { @@ -96,16 +97,17 @@ TEST_F(AddUsingTest, Apply) { struct { llvm::StringRef TestSource; llvm::StringRef ExpectedSource; - } Cases[]{{ - // Function, no other using, namespace. - R"cpp( + } Cases[]{ + { + // Function, no other using, namespace. + R"cpp( #include "test.hpp" namespace { void fun() { ^one::two::ff(); } })cpp", - R"cpp( + R"cpp( #include "test.hpp" namespace {using one::two::ff; @@ -113,17 +115,17 @@ void fun() { ff(); } })cpp", - }, - // Type, no other using, namespace. - { - R"cpp( + }, + // Type, no other using, namespace. + { + R"cpp( #include "test.hpp" namespace { void fun() { ::one::t^wo::cc inst; } })cpp", - R"cpp( + R"cpp( #include "test.hpp" namespace {using ::one::two::cc; @@ -131,16 +133,16 @@ void fun() { cc inst; } })cpp", - }, - // Type, no other using, no namespace. - { - R"cpp( + }, + // Type, no other using, no namespace. + { + R"cpp( #include "test.hpp" void fun() { one::two::e^e inst; })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::ee; @@ -148,9 +150,9 @@ using one::two::ee; void fun() { ee inst; })cpp"}, - // Function, other usings. - { - R"cpp( + // Function, other usings. + { + R"cpp( #include "test.hpp" using one::two::cc; @@ -161,7 +163,7 @@ void fun() { one::two::f^f(); } })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::cc; @@ -172,10 +174,10 @@ void fun() { ff(); } })cpp", - }, - // Function, other usings inside namespace. - { - R"cpp( + }, + // Function, other usings inside namespace. + { + R"cpp( #include "test.hpp" using one::two::cc; @@ -188,7 +190,7 @@ void fun() { o^ne::oo(); } })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::cc; @@ -201,9 +203,9 @@ void fun() { oo(); } })cpp"}, - // Using comes after cursor. - { - R"cpp( + // Using comes after cursor. + { + R"cpp( #include "test.hpp" namespace { @@ -215,7 +217,7 @@ void fun() { using one::two::cc; })cpp", - R"cpp( + R"cpp( #include "test.hpp" namespace {using one::two::ff; @@ -228,14 +230,14 @@ void fun() { using one::two::cc; })cpp"}, - // Pointer type. - {R"cpp( + // Pointer type. + {R"cpp( #include "test.hpp" void fun() { one::two::c^c *p; })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::cc; @@ -243,8 +245,8 @@ using one::two::cc; void fun() { cc *p; })cpp"}, - // Namespace declared via macro. - {R"cpp( + // Namespace declared via macro. + {R"cpp( #include "test.hpp" #define NS_BEGIN(name) namespace name { @@ -254,7 +256,7 @@ void fun() { one::two::f^f(); } })cpp", - R"cpp( + R"cpp( #include "test.hpp" #define NS_BEGIN(name) namespace name { @@ -266,15 +268,15 @@ void fun() { ff(); } })cpp"}, - // Inside macro argument. - {R"cpp( + // Inside macro argument. + {R"cpp( #include "test.hpp" #define CALL(name) name() void fun() { CALL(one::t^wo::ff); })cpp", - R"cpp( + R"cpp( #include "test.hpp" #define CALL(name) name() @@ -283,15 +285,15 @@ using one::two::ff; void fun() { CALL(ff); })cpp"}, - // Parent namespace != lexical parent namespace - {R"cpp( + // Parent namespace != lexical parent namespace + {R"cpp( #include "test.hpp" namespace foo { void fun(); } void foo::fun() { one::two::f^f(); })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::ff; @@ -300,8 +302,8 @@ namespace foo { void fun(); } void foo::fun() { ff(); })cpp"}, - // If all other using are fully qualified, add :: - {R"cpp( + // If all other using are fully qualified, add :: + {R"cpp( #include "test.hpp" using ::one::two::cc; @@ -310,7 +312,7 @@ using ::one::two::ee; void fun() { one::two::f^f(); })cpp", - R"cpp( + R"cpp( #include "test.hpp" using ::one::two::cc; @@ -319,8 +321,8 @@ using ::one::two::ff;using ::one::two::ee; void fun() { ff(); })cpp"}, - // Make sure we don't add :: if it's already there - {R"cpp( + // Make sure we don't add :: if it's already there + {R"cpp( #include "test.hpp" using ::one::two::cc; @@ -329,7 +331,7 @@ using ::one::two::ee; void fun() { ::one::two::f^f(); })cpp", - R"cpp( + R"cpp( #include "test.hpp" using ::one::two::cc; @@ -338,8 +340,8 @@ using ::one::two::ff;using ::one::two::ee; void fun() { ff(); })cpp"}, - // If even one using doesn't start with ::, do not add it - {R"cpp( + // If even one using doesn't start with ::, do not add it + {R"cpp( #include "test.hpp" using ::one::two::cc; @@ -348,7 +350,7 @@ using one::two::ee; void fun() { one::two::f^f(); })cpp", - R"cpp( + R"cpp( #include "test.hpp" using ::one::two::cc; @@ -357,14 +359,14 @@ using one::two::ff;using one::two::ee; void fun() { ff(); })cpp"}, - // using alias; insert using for the spelled name. - {R"cpp( + // using alias; insert using for the spelled name. + {R"cpp( #include "test.hpp" void fun() { one::u^u u; })cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::uu; @@ -372,29 +374,29 @@ using one::uu; void fun() { uu u; })cpp"}, - // using namespace. - {R"cpp( + // using namespace. + {R"cpp( #include "test.hpp" using namespace one; namespace { two::c^c C; })cpp", - R"cpp( + R"cpp( #include "test.hpp" using namespace one; namespace {using two::cc; cc C; })cpp"}, - // Type defined in main file, make sure using is after that. - {R"cpp( + // Type defined in main file, make sure using is after that. + {R"cpp( namespace xx { struct yy {}; } x^x::yy X; )cpp", - R"cpp( + R"cpp( namespace xx { struct yy {}; } @@ -403,8 +405,8 @@ using xx::yy; yy X; )cpp"}, - // Type defined in main file via "using", insert after that. - {R"cpp( + // Type defined in main file via "using", insert after that. + {R"cpp( #include "test.hpp" namespace xx { @@ -413,7 +415,7 @@ namespace xx { x^x::yy X; )cpp", - R"cpp( + R"cpp( #include "test.hpp" namespace xx { @@ -424,8 +426,8 @@ using xx::yy; yy X; )cpp"}, - // Using must come after function definition. - {R"cpp( + // Using must come after function definition. + {R"cpp( namespace xx { void yy(); } @@ -434,7 +436,7 @@ void fun() { x^x::yy(); } )cpp", - R"cpp( + R"cpp( namespace xx { void yy(); } @@ -445,23 +447,23 @@ void fun() { yy(); } )cpp"}, - // Existing using with non-namespace part. - {R"cpp( + // Existing using with non-namespace part. + {R"cpp( #include "test.hpp" using one::two::ee::ee_one; one::t^wo::cc c; )cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::two::cc;using one::two::ee::ee_one; cc c; )cpp"}, - // Template (like std::vector). - {R"cpp( + // Template (like std::vector). + {R"cpp( #include "test.hpp" one::v^ec foo; )cpp", - R"cpp( + R"cpp( #include "test.hpp" using one::vec;