Author: hokein Date: Wed Oct 11 07:00:42 2017 New Revision: 315459 URL: http://llvm.org/viewvc/llvm-project?rev=315459&view=rev Log: [clang-rename] Add more unittest.
Modified: cfe/trunk/unittests/Rename/RenameClassTest.cpp Modified: cfe/trunk/unittests/Rename/RenameClassTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameClassTest.cpp?rev=315459&r1=315458&r2=315459&view=diff ============================================================================== --- cfe/trunk/unittests/Rename/RenameClassTest.cpp (original) +++ cfe/trunk/unittests/Rename/RenameClassTest.cpp Wed Oct 11 07:00:42 2017 @@ -674,6 +674,124 @@ TEST_F(ClangRenameTest, ReferencesInLamb 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 <typename T> struct A {}; } + a::A<a::A<int>> foo;)"; + std::string Expected = R"( + namespace a { template <typename T> struct B {}; } + b::B<b::B<int>> foo;)"; + std::string After = runClangRenameOnCode(Before, "a::A", "b::B"); + CompareSnippets(Expected, After); +} + + } // anonymous namespace } // namespace test } // namespace clang_rename _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits