From 31636910b42a34d36b39dae09677b2e62b6f2c0d Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 11 Oct 2017 14:00:42 +0000 Subject: [PATCH] [clang-rename] Add more unittest. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315459 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Rename/RenameClassTest.cpp | 118 +++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/unittests/Rename/RenameClassTest.cpp b/unittests/Rename/RenameClassTest.cpp index 74280de787..f46126dff6 100644 --- a/unittests/Rename/RenameClassTest.cpp +++ b/unittests/Rename/RenameClassTest.cpp @@ -674,6 +674,124 @@ TEST_F(ClangRenameTest, ReferencesInLambdaFunctionParameters) { CompareSnippets(Expected, After); } +TEST_F(ClangRenameTest, DontChangeIfSameName) { + std::string Before = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(foo::Old * x) { + foo::Old::foo() ; + } + using foo::Old;)"; + std::string Expected = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(foo::Old * x) { + foo::Old::foo() ; + } + using foo::Old;)"; + std::string After = runClangRenameOnCode(Before, "foo::Old", "foo::Old"); + CompareSnippets(Expected, After); +} + +TEST_F(ClangRenameTest, ChangeIfNewNameWithLeadingDotDot) { + std::string Before = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(foo::Old * x) { + foo::Old::foo() ; + } + using foo::Old;)"; + std::string Expected = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(::foo::Old * x) { + ::foo::Old::foo() ; + } + using ::foo::Old;)"; + std::string After = runClangRenameOnCode(Before, "foo::Old", "::foo::Old"); + CompareSnippets(Expected, After); +} + +TEST_F(ClangRenameTest, ChangeIfSameNameWithLeadingDotDot) { + std::string Before = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(foo::Old * x) { + foo::Old::foo() ; + } + using foo::Old;)"; + std::string Expected = R"( + namespace foo { + class Old { + public: + static void foo() {} + }; + } + + void f(::foo::Old * x) { + ::foo::Old::foo() ; + } + using ::foo::Old;)"; + std::string After = runClangRenameOnCode(Before, "::foo::Old", "::foo::Old"); + CompareSnippets(Expected, After); +} + +TEST_F(RenameClassTest, UsingAlias) { + std::string Before = R"( + namespace a { struct A {}; } + + namespace foo { + using Alias = a::A; + Alias a; + })"; + std::string Expected = R"( + namespace a { struct B {}; } + + namespace foo { + using Alias = b::B; + Alias a; + })"; + std::string After = runClangRenameOnCode(Before, "a::A", "b::B"); + CompareSnippets(Expected, After); +} + +TEST_F(ClangRenameTest, NestedTemplates) { + std::string Before = R"( + namespace a { template struct A {}; } + a::A> foo;)"; + std::string Expected = R"( + namespace a { template struct B {}; } + b::B> foo;)"; + std::string After = runClangRenameOnCode(Before, "a::A", "b::B"); + CompareSnippets(Expected, After); +} + + } // anonymous namespace } // namespace test } // namespace clang_rename -- 2.40.0