]> granicus.if.org Git - clang/commitdiff
[clang-rename] Add more unittest.
authorHaojian Wu <hokein@google.com>
Wed, 11 Oct 2017 14:00:42 +0000 (14:00 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 11 Oct 2017 14:00:42 +0000 (14:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315459 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Rename/RenameClassTest.cpp

index 74280de7871b6e9c7c919fc75b219baa02ef0e64..f46126dff667a8d8066ce23eda132aa975b15a98 100644 (file)
@@ -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 <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