summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/TweakTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/unittests/TweakTests.cpp')
-rw-r--r--clang-tools-extra/clangd/unittests/TweakTests.cpp704
1 files changed, 0 insertions, 704 deletions
diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index 2a6744b81d9..c5caa4b7dc5 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -24,8 +24,6 @@
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -35,23 +33,15 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cassert>
-#include <string>
-#include <utility>
-#include <vector>
using ::testing::AllOf;
using ::testing::HasSubstr;
using ::testing::StartsWith;
-using ::testing::ElementsAre;
namespace clang {
namespace clangd {
namespace {
-MATCHER_P2(FileWithContents, FileName, Contents, "") {
- return arg.first() == FileName && arg.second == Contents;
-}
-
TEST(FileEdits, AbsolutePath) {
auto RelPaths = {"a.h", "foo.cpp", "test/test.cpp"};
@@ -890,700 +880,6 @@ TEST_F(RemoveUsingNamespaceTest, All) {
EXPECT_EQ(C.second, apply(C.first)) << C.first;
}
-TWEAK_TEST(DefineInline);
-TEST_F(DefineInlineTest, TriggersOnFunctionDecl) {
- // Basic check for function body and signature.
- EXPECT_AVAILABLE(R"cpp(
- class Bar {
- void baz();
- };
-
- [[void [[Bar::[[b^a^z]]]]() [[{
- return;
- }]]]]
-
- void foo();
- [[void [[f^o^o]]() [[{
- return;
- }]]]]
- )cpp");
-
- EXPECT_UNAVAILABLE(R"cpp(
- // Not a definition
- vo^i[[d^ ^f]]^oo();
-
- [[vo^id ]]foo[[()]] {[[
- [[(void)(5+3);
- return;]]
- }]]
- )cpp");
-}
-
-TEST_F(DefineInlineTest, NoForwardDecl) {
- Header = "void bar();";
- EXPECT_UNAVAILABLE(R"cpp(
- void bar() {
- return;
- }
- // FIXME: Generate a decl in the header.
- void fo^o() {
- return;
- })cpp");
-}
-
-TEST_F(DefineInlineTest, ReferencedDecls) {
- EXPECT_AVAILABLE(R"cpp(
- void bar();
- void foo(int test);
-
- void fo^o(int baz) {
- int x = 10;
- bar();
- })cpp");
-
- // Internal symbol usage.
- Header = "void foo(int test);";
- EXPECT_UNAVAILABLE(R"cpp(
- void bar();
- void fo^o(int baz) {
- int x = 10;
- bar();
- })cpp");
-
- // Becomes available after making symbol visible.
- Header = "void bar();" + Header;
- EXPECT_AVAILABLE(R"cpp(
- void fo^o(int baz) {
- int x = 10;
- bar();
- })cpp");
-
- // FIXME: Move declaration below bar to make it visible.
- Header.clear();
- EXPECT_UNAVAILABLE(R"cpp(
- void foo();
- void bar();
-
- void fo^o() {
- bar();
- })cpp");
-
- // Order doesn't matter within a class.
- EXPECT_AVAILABLE(R"cpp(
- class Bar {
- void foo();
- void bar();
- };
-
- void Bar::fo^o() {
- bar();
- })cpp");
-
- // FIXME: Perform include insertion to make symbol visible.
- ExtraFiles["a.h"] = "void bar();";
- Header = "void foo(int test);";
- EXPECT_UNAVAILABLE(R"cpp(
- #include "a.h"
- void fo^o(int baz) {
- int x = 10;
- bar();
- })cpp");
-}
-
-TEST_F(DefineInlineTest, TemplateSpec) {
- EXPECT_UNAVAILABLE(R"cpp(
- template <typename T> void foo();
- template<> void foo<char>();
-
- template<> void f^oo<int>() {
- })cpp");
- EXPECT_UNAVAILABLE(R"cpp(
- template <typename T> void foo();
-
- template<> void f^oo<int>() {
- })cpp");
- EXPECT_UNAVAILABLE(R"cpp(
- template <typename T> struct Foo { void foo(); };
-
- template <typename T> void Foo<T>::f^oo() {
- })cpp");
- EXPECT_AVAILABLE(R"cpp(
- template <typename T> void foo();
- void bar();
- template <> void foo<int>();
-
- template<> void f^oo<int>() {
- bar();
- })cpp");
-}
-
-TEST_F(DefineInlineTest, CheckForCanonDecl) {
- EXPECT_UNAVAILABLE(R"cpp(
- void foo();
-
- void bar() {}
- void f^oo() {
- // This bar normally refers to the definition just above, but it is not
- // visible from the forward declaration of foo.
- bar();
- })cpp");
- // Make it available with a forward decl.
- EXPECT_AVAILABLE(R"cpp(
- void bar();
- void foo();
-
- void bar() {}
- void f^oo() {
- bar();
- })cpp");
-}
-
-TEST_F(DefineInlineTest, UsingShadowDecls) {
- EXPECT_UNAVAILABLE(R"cpp(
- namespace ns1 { void foo(int); }
- namespace ns2 { void foo(int*); }
- template <typename T>
- void bar();
-
- using ns1::foo;
- using ns2::foo;
-
- template <typename T>
- void b^ar() {
- foo(T());
- })cpp");
-}
-
-TEST_F(DefineInlineTest, TransformNestedNamespaces) {
- auto Test = R"cpp(
- namespace a {
- void bar();
- namespace b {
- void baz();
- namespace c {
- void aux();
- }
- }
- }
-
- void foo();
- using namespace a;
- using namespace b;
- using namespace c;
- void f^oo() {
- bar();
- a::bar();
-
- baz();
- b::baz();
- a::b::baz();
-
- aux();
- c::aux();
- b::c::aux();
- a::b::c::aux();
- })cpp";
- auto Expected = R"cpp(
- namespace a {
- void bar();
- namespace b {
- void baz();
- namespace c {
- void aux();
- }
- }
- }
-
- void foo(){
- a::bar();
- a::bar();
-
- a::b::baz();
- a::b::baz();
- a::b::baz();
-
- a::b::c::aux();
- a::b::c::aux();
- a::b::c::aux();
- a::b::c::aux();
- }
- using namespace a;
- using namespace b;
- using namespace c;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformUsings) {
- auto Test = R"cpp(
- namespace a { namespace b { namespace c { void aux(); } } }
-
- void foo();
- void f^oo() {
- using namespace a;
- using namespace b;
- using namespace c;
- using c::aux;
- namespace d = c;
- })cpp";
- auto Expected = R"cpp(
- namespace a { namespace b { namespace c { void aux(); } } }
-
- void foo(){
- using namespace a;
- using namespace a::b;
- using namespace a::b::c;
- using a::b::c::aux;
- namespace d = a::b::c;
- }
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformDecls) {
- auto Test = R"cpp(
- void foo();
- void f^oo() {
- class Foo {
- public:
- void foo();
- int x;
- static int y;
- };
- Foo::y = 0;
-
- enum En { Zero, One };
- En x = Zero;
-
- enum class EnClass { Zero, One };
- EnClass y = EnClass::Zero;
- })cpp";
- auto Expected = R"cpp(
- void foo(){
- class Foo {
- public:
- void foo();
- int x;
- static int y;
- };
- Foo::y = 0;
-
- enum En { Zero, One };
- En x = Zero;
-
- enum class EnClass { Zero, One };
- EnClass y = EnClass::Zero;
- }
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformTemplDecls) {
- auto Test = R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- void bar();
- };
- template <typename T> T bar;
- template <typename T> void aux() {}
- }
-
- void foo();
-
- using namespace a;
- void f^oo() {
- bar<Bar<int>>.bar();
- aux<Bar<int>>();
- })cpp";
- auto Expected = R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- void bar();
- };
- template <typename T> T bar;
- template <typename T> void aux() {}
- }
-
- void foo(){
- a::bar<a::Bar<int>>.bar();
- a::aux<a::Bar<int>>();
- }
-
- using namespace a;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformMembers) {
- auto Test = R"cpp(
- class Foo {
- void foo();
- };
-
- void Foo::f^oo() {
- return;
- })cpp";
- auto Expected = R"cpp(
- class Foo {
- void foo(){
- return;
- }
- };
-
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-
- ExtraFiles["a.h"] = R"cpp(
- class Foo {
- void foo();
- };)cpp";
-
- llvm::StringMap<std::string> EditedFiles;
- Test = R"cpp(
- #include "a.h"
- void Foo::f^oo() {
- return;
- })cpp";
- Expected = R"cpp(
- #include "a.h"
- )cpp";
- EXPECT_EQ(apply(Test, &EditedFiles), Expected);
-
- Expected = R"cpp(
- class Foo {
- void foo(){
- return;
- }
- };)cpp";
- EXPECT_THAT(EditedFiles,
- ElementsAre(FileWithContents(testPath("a.h"), Expected)));
-}
-
-TEST_F(DefineInlineTest, TransformDependentTypes) {
- auto Test = R"cpp(
- namespace a {
- template <typename T> class Bar {};
- }
-
- template <typename T>
- void foo();
-
- using namespace a;
- template <typename T>
- void f^oo() {
- Bar<T> B;
- Bar<Bar<T>> q;
- })cpp";
- auto Expected = R"cpp(
- namespace a {
- template <typename T> class Bar {};
- }
-
- template <typename T>
- void foo(){
- a::Bar<T> B;
- a::Bar<a::Bar<T>> q;
- }
-
- using namespace a;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformFunctionTempls) {
- // Check we select correct specialization decl.
- std::pair<llvm::StringRef, llvm::StringRef> Cases[] = {
- {R"cpp(
- template <typename T>
- void foo(T p);
-
- template <>
- void foo<int>(int p);
-
- template <>
- void foo<char>(char p);
-
- template <>
- void fo^o<int>(int p) {
- return;
- })cpp",
- R"cpp(
- template <typename T>
- void foo(T p);
-
- template <>
- void foo<int>(int p){
- return;
- }
-
- template <>
- void foo<char>(char p);
-
- )cpp"},
- {// Make sure we are not selecting the first specialization all the time.
- R"cpp(
- template <typename T>
- void foo(T p);
-
- template <>
- void foo<int>(int p);
-
- template <>
- void foo<char>(char p);
-
- template <>
- void fo^o<char>(char p) {
- return;
- })cpp",
- R"cpp(
- template <typename T>
- void foo(T p);
-
- template <>
- void foo<int>(int p);
-
- template <>
- void foo<char>(char p){
- return;
- }
-
- )cpp"},
- {R"cpp(
- template <typename T>
- void foo(T p);
-
- template <>
- void foo<int>(int p);
-
- template <typename T>
- void fo^o(T p) {
- return;
- })cpp",
- R"cpp(
- template <typename T>
- void foo(T p){
- return;
- }
-
- template <>
- void foo<int>(int p);
-
- )cpp"},
- };
- for(const auto &Case : Cases)
- EXPECT_EQ(apply(Case.first), Case.second) << Case.first;
-}
-
-TEST_F(DefineInlineTest, TransformTypeLocs) {
- auto Test = R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- template <typename Q> class Baz {};
- };
- class Foo{};
- }
-
- void foo();
-
- using namespace a;
- void f^oo() {
- Bar<int> B;
- Foo foo;
- a::Bar<Bar<int>>::Baz<Bar<int>> q;
- })cpp";
- auto Expected = R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- template <typename Q> class Baz {};
- };
- class Foo{};
- }
-
- void foo(){
- a::Bar<int> B;
- a::Foo foo;
- a::Bar<a::Bar<int>>::Baz<a::Bar<int>> q;
- }
-
- using namespace a;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformDeclRefs) {
- auto Test =R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- void foo();
- static void bar();
- int x;
- static int y;
- };
- void bar();
- void test();
- }
-
- void foo();
- using namespace a;
- void f^oo() {
- a::Bar<int> B;
- B.foo();
- a::bar();
- Bar<Bar<int>>::bar();
- a::Bar<int>::bar();
- B.x = Bar<int>::y;
- Bar<int>::y = 3;
- bar();
- a::test();
- })cpp";
- auto Expected = R"cpp(
- namespace a {
- template <typename T> class Bar {
- public:
- void foo();
- static void bar();
- int x;
- static int y;
- };
- void bar();
- void test();
- }
-
- void foo(){
- a::Bar<int> B;
- B.foo();
- a::bar();
- a::Bar<a::Bar<int>>::bar();
- a::Bar<int>::bar();
- B.x = a::Bar<int>::y;
- a::Bar<int>::y = 3;
- a::bar();
- a::test();
- }
- using namespace a;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, StaticMembers) {
- auto Test = R"cpp(
- namespace ns { class X { static void foo(); void bar(); }; }
- void ns::X::b^ar() {
- foo();
- })cpp";
- auto Expected = R"cpp(
- namespace ns { class X { static void foo(); void bar(){
- foo();
- } }; }
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TransformInlineNamespaces) {
- auto Test = R"cpp(
- namespace a { inline namespace b { namespace { struct Foo{}; } } }
- void foo();
-
- using namespace a;
- void ^foo() {Foo foo;})cpp";
- auto Expected = R"cpp(
- namespace a { inline namespace b { namespace { struct Foo{}; } } }
- void foo(){a::Foo foo;}
-
- using namespace a;
- )cpp";
- EXPECT_EQ(apply(Test), Expected);
-}
-
-TEST_F(DefineInlineTest, TokensBeforeSemicolon) {
- std::pair<llvm::StringRef, llvm::StringRef> Cases[] = {
- {R"cpp(
- void foo() /*Comment -_-*/ /*Com 2*/ ;
- void fo^o() { return ; })cpp",
- R"cpp(
- void foo() /*Comment -_-*/ /*Com 2*/ { return ; }
- )cpp"},
-
- {R"cpp(
- void foo();
- void fo^o() { return ; })cpp",
- R"cpp(
- void foo(){ return ; }
- )cpp"},
-
- {R"cpp(
- #define SEMI ;
- void foo() SEMI
- void fo^o() { return ; })cpp",
- "fail: Couldn't find semicolon for target declaration."},
- };
- for(const auto& Case: Cases)
- EXPECT_EQ(apply(Case.first), Case.second) << Case.first;
-}
-
-TEST_F(DefineInlineTest, HandleMacros) {
- EXPECT_UNAVAILABLE(R"cpp(
- #define BODY { return; }
- void foo();
- void f^oo()BODY)cpp");
-
- EXPECT_UNAVAILABLE(R"cpp(
- #define BODY void foo(){ return; }
- void foo();
- [[BODY]])cpp");
-
- std::pair<llvm::StringRef, llvm::StringRef> Cases[] = {
- // We don't qualify declarations coming from macros.
- {R"cpp(
- #define BODY Foo
- namespace a { class Foo{}; }
- void foo();
- using namespace a;
- void f^oo(){BODY})cpp",
- R"cpp(
- #define BODY Foo
- namespace a { class Foo{}; }
- void foo(){BODY}
- using namespace a;
- )cpp"},
-
- // Macro is not visible at declaration location, but we proceed.
- {R"cpp(
- void foo();
- #define BODY return;
- void f^oo(){BODY})cpp",
- R"cpp(
- void foo(){BODY}
- #define BODY return;
- )cpp"},
-
- {R"cpp(
- #define TARGET void foo()
- TARGET;
- void f^oo(){ return; })cpp",
- R"cpp(
- #define TARGET void foo()
- TARGET{ return; }
- )cpp"},
-
- {R"cpp(
- #define TARGET foo
- void TARGET();
- void f^oo(){ return; })cpp",
- R"cpp(
- #define TARGET foo
- void TARGET(){ return; }
- )cpp"},
- };
- for(const auto& Case: Cases)
- EXPECT_EQ(apply(Case.first), Case.second) << Case.first;
-}
-
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud