summaryrefslogtreecommitdiff
path: root/test/clang-rename
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-06-30 16:36:09 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-06-30 16:36:09 +0000
commit4803aff743e866df42dd12fd37093bf2b4af42ac (patch)
tree3444ad9cff30fbdde5ea2d2f7b30a33a3bb69b33 /test/clang-rename
parentfc0baba7f6ae7a67b39c2375bfbbb7948a10b026 (diff)
[refactor] Move clang-rename into the clang repository
The core engine of clang-rename will be used for local and global renames in the new refactoring engine, as mentioned in http://lists.llvm.org/pipermail/cfe-dev/2017-June/054286.html. The clang-rename tool is still supported but might get deprecated in the future. Differential Revision: https://reviews.llvm.org/D34696 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/clang-rename')
-rw-r--r--test/clang-rename/ClassAsTemplateArgument.cpp21
-rw-r--r--test/clang-rename/ClassFindByName.cpp10
-rw-r--r--test/clang-rename/ClassReplacements.cpp11
-rw-r--r--test/clang-rename/ClassSimpleRenaming.cpp14
-rw-r--r--test/clang-rename/ClassTestMulti.cpp11
-rw-r--r--test/clang-rename/ClassTestMultiByName.cpp8
-rw-r--r--test/clang-rename/ComplexFunctionOverride.cpp47
-rw-r--r--test/clang-rename/ComplicatedClassType.cpp63
-rw-r--r--test/clang-rename/Ctor.cpp14
-rw-r--r--test/clang-rename/CtorInitializer.cpp17
-rw-r--r--test/clang-rename/DeclRefExpr.cpp24
-rw-r--r--test/clang-rename/Field.cpp15
-rw-r--r--test/clang-rename/FunctionMacro.cpp20
-rw-r--r--test/clang-rename/FunctionOverride.cpp13
-rw-r--r--test/clang-rename/FunctionWithClassFindByName.cpp12
-rw-r--r--test/clang-rename/IncludeHeaderWithSymbol.cpp10
-rw-r--r--test/clang-rename/Inputs/HeaderWithSymbol.h1
-rw-r--r--test/clang-rename/Inputs/OffsetToNewName.yaml6
-rw-r--r--test/clang-rename/Inputs/QualifiedNameToNewName.yaml6
-rw-r--r--test/clang-rename/InvalidNewName.cpp2
-rw-r--r--test/clang-rename/InvalidOffset.cpp9
-rw-r--r--test/clang-rename/InvalidQualifiedName.cpp4
-rw-r--r--test/clang-rename/MemberExprMacro.cpp22
-rw-r--r--test/clang-rename/Namespace.cpp13
-rw-r--r--test/clang-rename/NoNewName.cpp4
-rw-r--r--test/clang-rename/TemplateClassInstantiation.cpp42
-rw-r--r--test/clang-rename/TemplateTypename.cpp24
-rw-r--r--test/clang-rename/TemplatedClassFunction.cpp22
-rw-r--r--test/clang-rename/UserDefinedConversion.cpp26
-rw-r--r--test/clang-rename/Variable.cpp33
-rw-r--r--test/clang-rename/VariableMacro.cpp21
-rw-r--r--test/clang-rename/YAMLInput.cpp10
32 files changed, 555 insertions, 0 deletions
diff --git a/test/clang-rename/ClassAsTemplateArgument.cpp b/test/clang-rename/ClassAsTemplateArgument.cpp
new file mode 100644
index 0000000000..2e09a5b529
--- /dev/null
+++ b/test/clang-rename/ClassAsTemplateArgument.cpp
@@ -0,0 +1,21 @@
+class Foo /* Test 1 */ {}; // CHECK: class Bar /* Test 1 */ {};
+
+template <typename T>
+void func() {}
+
+template <typename T>
+class Baz {};
+
+int main() {
+ func<Foo>(); // CHECK: func<Bar>();
+ Baz<Foo> /* Test 2 */ obj; // CHECK: Baz<Bar> /* Test 2 */ obj;
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=215 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/ClassFindByName.cpp b/test/clang-rename/ClassFindByName.cpp
new file mode 100644
index 0000000000..4430891ec4
--- /dev/null
+++ b/test/clang-rename/ClassFindByName.cpp
@@ -0,0 +1,10 @@
+class Foo { // CHECK: class Bar {
+};
+
+int main() {
+ Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
diff --git a/test/clang-rename/ClassReplacements.cpp b/test/clang-rename/ClassReplacements.cpp
new file mode 100644
index 0000000000..2b478bbf90
--- /dev/null
+++ b/test/clang-rename/ClassReplacements.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/fixes
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=254 -new-name=Bar -export-fixes=%t/fixes/clang-rename.yaml %t.cpp --
+// RUN: clang-apply-replacements %t
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+class Foo {}; // CHECK: class Bar {};
+
+// Use grep -FUbo 'Foo' <file> to get the correct offset of Cla when changing
+// this file.
diff --git a/test/clang-rename/ClassSimpleRenaming.cpp b/test/clang-rename/ClassSimpleRenaming.cpp
new file mode 100644
index 0000000000..086f55736c
--- /dev/null
+++ b/test/clang-rename/ClassSimpleRenaming.cpp
@@ -0,0 +1,14 @@
+class Foo /* Test 1 */ { // CHECK: class Bar /* Test 1 */ {
+public:
+ void foo(int x);
+};
+
+void Foo::foo(int x) /* Test 2 */ {} // CHECK: void Bar::foo(int x) /* Test 2 */ {}
+
+// Test 1.
+// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=109 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/ClassTestMulti.cpp b/test/clang-rename/ClassTestMulti.cpp
new file mode 100644
index 0000000000..81e65c7606
--- /dev/null
+++ b/test/clang-rename/ClassTestMulti.cpp
@@ -0,0 +1,11 @@
+class Foo1 /* Offset 1 */ { // CHECK: class Bar1 /* Offset 1 */ {
+};
+
+class Foo2 /* Offset 2 */ { // CHECK: class Bar2 /* Offset 2 */ {
+};
+
+// Test 1.
+// RUN: clang-rename -offset=6 -new-name=Bar1 -offset=76 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/ClassTestMultiByName.cpp b/test/clang-rename/ClassTestMultiByName.cpp
new file mode 100644
index 0000000000..61b69a1bdf
--- /dev/null
+++ b/test/clang-rename/ClassTestMultiByName.cpp
@@ -0,0 +1,8 @@
+class Foo1 { // CHECK: class Bar1
+};
+
+class Foo2 { // CHECK: class Bar2
+};
+
+// Test 1.
+// RUN: clang-rename -qualified-name=Foo1 -new-name=Bar1 -qualified-name=Foo2 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s
diff --git a/test/clang-rename/ComplexFunctionOverride.cpp b/test/clang-rename/ComplexFunctionOverride.cpp
new file mode 100644
index 0000000000..ccf3a20e54
--- /dev/null
+++ b/test/clang-rename/ComplexFunctionOverride.cpp
@@ -0,0 +1,47 @@
+struct A {
+ virtual void foo() {} /* Test 1 */ // CHECK: virtual void bar() {}
+};
+
+struct B : A {
+ void foo() override {} /* Test 2 */ // CHECK: void bar() override {}
+};
+
+struct C : B {
+ void foo() override {} /* Test 3 */ // CHECK: void bar() override {}
+};
+
+struct D : B {
+ void foo() override {} /* Test 4 */ // CHECK: void bar() override {}
+};
+
+struct E : D {
+ void foo() override {} /* Test 5 */ // CHECK: void bar() override {}
+};
+
+int main() {
+ A a;
+ a.foo(); // CHECK: a.bar();
+ B b;
+ b.foo(); // CHECK: b.bar();
+ C c;
+ c.foo(); // CHECK: c.bar();
+ D d;
+ d.foo(); // CHECK: d.bar();
+ E e;
+ e.foo(); // CHECK: e.bar();
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=26 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=109 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=201 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=293 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 5.
+// RUN: clang-rename -offset=385 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'foo.*' <file>
diff --git a/test/clang-rename/ComplicatedClassType.cpp b/test/clang-rename/ComplicatedClassType.cpp
new file mode 100644
index 0000000000..8801953031
--- /dev/null
+++ b/test/clang-rename/ComplicatedClassType.cpp
@@ -0,0 +1,63 @@
+// Forward declaration.
+class Foo; /* Test 1 */ // CHECK: class Bar; /* Test 1 */
+
+class Baz {
+ virtual int getValue() const = 0;
+};
+
+class Foo : public Baz { /* Test 2 */// CHECK: class Bar : public Baz {
+public:
+ Foo(int value = 0) : x(value) {} // CHECK: Bar(int value = 0) : x(value) {}
+
+ Foo &operator++(int) { // CHECK: Bar &operator++(int) {
+ x++;
+ return *this;
+ }
+
+ bool operator<(Foo const &rhs) { // CHECK: bool operator<(Bar const &rhs) {
+ return this->x < rhs.x;
+ }
+
+ int getValue() const {
+ return 0;
+ }
+
+private:
+ int x;
+};
+
+int main() {
+ Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
+ Foo Variable = Foo(10); // CHECK: Bar Variable = Bar(10);
+ for (Foo it; it < Variable; it++) { // CHECK: for (Bar it; it < Variable; it++) {
+ }
+ const Foo *C = new Foo(); // CHECK: const Bar *C = new Bar();
+ const_cast<Foo *>(C)->getValue(); // CHECK: const_cast<Bar *>(C)->getValue();
+ Foo foo; // CHECK: Bar foo;
+ const Baz &BazReference = foo;
+ const Baz *BazPointer = &foo;
+ dynamic_cast<const Foo &>(BazReference).getValue(); /* Test 3 */ // CHECK: dynamic_cast<const Bar &>(BazReference).getValue();
+ dynamic_cast<const Foo *>(BazPointer)->getValue(); /* Test 4 */ // CHECK: dynamic_cast<const Bar *>(BazPointer)->getValue();
+ reinterpret_cast<const Foo *>(BazPointer)->getValue(); /* Test 5 */ // CHECK: reinterpret_cast<const Bar *>(BazPointer)->getValue();
+ static_cast<const Foo &>(BazReference).getValue(); /* Test 6 */ // CHECK: static_cast<const Bar &>(BazReference).getValue();
+ static_cast<const Foo *>(BazPointer)->getValue(); /* Test 7 */ // CHECK: static_cast<const Bar *>(BazPointer)->getValue();
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=30 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=155 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=1133 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=1266 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 5.
+// RUN: clang-rename -offset=1402 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 6.
+// RUN: clang-rename -offset=1533 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+// Test 7.
+// RUN: clang-rename -offset=1665 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/Ctor.cpp b/test/clang-rename/Ctor.cpp
new file mode 100644
index 0000000000..9908a4123d
--- /dev/null
+++ b/test/clang-rename/Ctor.cpp
@@ -0,0 +1,14 @@
+class Foo { // CHECK: class Bar {
+public:
+ Foo(); /* Test 1 */ // CHECK: Bar();
+};
+
+Foo::Foo() /* Test 2 */ {} // CHECK: Bar::Bar() /* Test 2 */ {}
+
+// Test 1.
+// RUN: clang-rename -offset=62 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=116 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/CtorInitializer.cpp b/test/clang-rename/CtorInitializer.cpp
new file mode 100644
index 0000000000..fed4f5b06c
--- /dev/null
+++ b/test/clang-rename/CtorInitializer.cpp
@@ -0,0 +1,17 @@
+class Baz {};
+
+class Qux {
+ Baz Foo; /* Test 1 */ // CHECK: Baz Bar;
+public:
+ Qux();
+};
+
+Qux::Qux() : Foo() /* Test 2 */ {} // CHECK: Qux::Qux() : Bar() /* Test 2 */ {}
+
+// Test 1.
+// RUN: clang-rename -offset=33 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=118 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/DeclRefExpr.cpp b/test/clang-rename/DeclRefExpr.cpp
new file mode 100644
index 0000000000..6462862d82
--- /dev/null
+++ b/test/clang-rename/DeclRefExpr.cpp
@@ -0,0 +1,24 @@
+class C {
+public:
+ static int Foo; /* Test 1 */ // CHECK: static int Bar;
+};
+
+int foo(int x) { return 0; }
+#define MACRO(a) foo(a)
+
+int main() {
+ C::Foo = 1; /* Test 2 */ // CHECK: C::Bar = 1;
+ MACRO(C::Foo); // CHECK: MACRO(C::Bar);
+ int y = C::Foo; /* Test 3 */ // CHECK: int y = C::Bar;
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=31 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=152 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=271 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/Field.cpp b/test/clang-rename/Field.cpp
new file mode 100644
index 0000000000..c0e9a019e4
--- /dev/null
+++ b/test/clang-rename/Field.cpp
@@ -0,0 +1,15 @@
+class Baz {
+ int Foo; /* Test 1 */ // CHECK: int Bar;
+public:
+ Baz();
+};
+
+Baz::Baz() : Foo(0) /* Test 2 */ {} // CHECK: Baz::Baz() : Bar(0)
+
+// Test 1.
+// RUN: clang-rename -offset=18 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=89 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/FunctionMacro.cpp b/test/clang-rename/FunctionMacro.cpp
new file mode 100644
index 0000000000..6e87026ec7
--- /dev/null
+++ b/test/clang-rename/FunctionMacro.cpp
@@ -0,0 +1,20 @@
+#define moo foo // CHECK: #define moo macro_function
+
+int foo() /* Test 1 */ { // CHECK: int macro_function() /* Test 1 */ {
+ return 42;
+}
+
+void boo(int value) {}
+
+void qoo() {
+ foo(); // CHECK: macro_function();
+ boo(foo()); // CHECK: boo(macro_function());
+ moo();
+ boo(moo());
+}
+
+// Test 1.
+// RUN: clang-rename -offset=68 -new-name=macro_function %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'foo.*' <file>
diff --git a/test/clang-rename/FunctionOverride.cpp b/test/clang-rename/FunctionOverride.cpp
new file mode 100644
index 0000000000..adfeb739e6
--- /dev/null
+++ b/test/clang-rename/FunctionOverride.cpp
@@ -0,0 +1,13 @@
+class A { virtual void foo(); /* Test 1 */ }; // CHECK: class A { virtual void bar();
+class B : public A { void foo(); /* Test 2 */ }; // CHECK: class B : public A { void bar();
+class C : public B { void foo(); /* Test 3 */ }; // CHECK: class C : public B { void bar();
+
+// Test 1.
+// RUN: clang-rename -offset=23 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=116 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=209 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'foo.*' <file>
diff --git a/test/clang-rename/FunctionWithClassFindByName.cpp b/test/clang-rename/FunctionWithClassFindByName.cpp
new file mode 100644
index 0000000000..2cae09a1c2
--- /dev/null
+++ b/test/clang-rename/FunctionWithClassFindByName.cpp
@@ -0,0 +1,12 @@
+void foo() {
+}
+
+class Foo { // CHECK: class Bar
+};
+
+int main() {
+ Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
+ return 0;
+}
+
+// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
diff --git a/test/clang-rename/IncludeHeaderWithSymbol.cpp b/test/clang-rename/IncludeHeaderWithSymbol.cpp
new file mode 100644
index 0000000000..cb2baee57b
--- /dev/null
+++ b/test/clang-rename/IncludeHeaderWithSymbol.cpp
@@ -0,0 +1,10 @@
+#include "Inputs/HeaderWithSymbol.h"
+
+int main() {
+ return 0; // CHECK: {{^ return 0;}}
+}
+
+// Test 1.
+// The file IncludeHeaderWithSymbol.cpp doesn't contain the symbol Foo
+// and is expected to be written to stdout without modifications
+// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | FileCheck %s
diff --git a/test/clang-rename/Inputs/HeaderWithSymbol.h b/test/clang-rename/Inputs/HeaderWithSymbol.h
new file mode 100644
index 0000000000..1fe02e8978
--- /dev/null
+++ b/test/clang-rename/Inputs/HeaderWithSymbol.h
@@ -0,0 +1 @@
+struct Foo {};
diff --git a/test/clang-rename/Inputs/OffsetToNewName.yaml b/test/clang-rename/Inputs/OffsetToNewName.yaml
new file mode 100644
index 0000000000..d8e972880f
--- /dev/null
+++ b/test/clang-rename/Inputs/OffsetToNewName.yaml
@@ -0,0 +1,6 @@
+---
+- Offset: 6
+ NewName: Bar1
+- Offset: 44
+ NewName: Bar2
+...
diff --git a/test/clang-rename/Inputs/QualifiedNameToNewName.yaml b/test/clang-rename/Inputs/QualifiedNameToNewName.yaml
new file mode 100644
index 0000000000..6e3783671d
--- /dev/null
+++ b/test/clang-rename/Inputs/QualifiedNameToNewName.yaml
@@ -0,0 +1,6 @@
+---
+- QualifiedName: Foo1
+ NewName: Bar1
+- QualifiedName: Foo2
+ NewName: Bar2
+...
diff --git a/test/clang-rename/InvalidNewName.cpp b/test/clang-rename/InvalidNewName.cpp
new file mode 100644
index 0000000000..e6b38e5942
--- /dev/null
+++ b/test/clang-rename/InvalidNewName.cpp
@@ -0,0 +1,2 @@
+// RUN: not clang-rename -new-name=class -offset=133 %s 2>&1 | FileCheck %s
+// CHECK: ERROR: new name is not a valid identifier in C++17.
diff --git a/test/clang-rename/InvalidOffset.cpp b/test/clang-rename/InvalidOffset.cpp
new file mode 100644
index 0000000000..2ae04d01e4
--- /dev/null
+++ b/test/clang-rename/InvalidOffset.cpp
@@ -0,0 +1,9 @@
+#include "Inputs/HeaderWithSymbol.h"
+#define FOO int bar;
+FOO
+
+int foo;
+
+// RUN: not clang-rename -new-name=qux -offset=259 %s -- 2>&1 | FileCheck %s
+// CHECK-NOT: CHECK
+// CHECK: error: SourceLocation in file {{.*}}InvalidOffset.cpp at offset 259 is invalid
diff --git a/test/clang-rename/InvalidQualifiedName.cpp b/test/clang-rename/InvalidQualifiedName.cpp
new file mode 100644
index 0000000000..5280e3939c
--- /dev/null
+++ b/test/clang-rename/InvalidQualifiedName.cpp
@@ -0,0 +1,4 @@
+struct S {
+};
+
+// RUN: clang-rename -force -qualified-name S2 -new-name=T %s --
diff --git a/test/clang-rename/MemberExprMacro.cpp b/test/clang-rename/MemberExprMacro.cpp
new file mode 100644
index 0000000000..56cd8d95f6
--- /dev/null
+++ b/test/clang-rename/MemberExprMacro.cpp
@@ -0,0 +1,22 @@
+class Baz {
+public:
+ int Foo; /* Test 1 */ // CHECK: int Bar;
+};
+
+int qux(int x) { return 0; }
+#define MACRO(a) qux(a)
+
+int main() {
+ Baz baz;
+ baz.Foo = 1; /* Test 2 */ // CHECK: baz.Bar = 1;
+ MACRO(baz.Foo); // CHECK: MACRO(baz.Bar);
+ int y = baz.Foo; // CHECK: int y = baz.Bar;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=26 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=155 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/Namespace.cpp b/test/clang-rename/Namespace.cpp
new file mode 100644
index 0000000000..ec9630fded
--- /dev/null
+++ b/test/clang-rename/Namespace.cpp
@@ -0,0 +1,13 @@
+namespace gcc /* Test 1 */ { // CHECK: namespace clang /* Test 1 */ {
+ int x;
+}
+
+void boo() {
+ gcc::x = 42; // CHECK: clang::x = 42;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=10 -new-name=clang %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/NoNewName.cpp b/test/clang-rename/NoNewName.cpp
new file mode 100644
index 0000000000..4f882d83b0
--- /dev/null
+++ b/test/clang-rename/NoNewName.cpp
@@ -0,0 +1,4 @@
+// Check for an error while -new-name argument has not been passed to
+// clang-rename.
+// RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s
+// CHECK: clang-rename: -new-name must be specified.
diff --git a/test/clang-rename/TemplateClassInstantiation.cpp b/test/clang-rename/TemplateClassInstantiation.cpp
new file mode 100644
index 0000000000..493d0951df
--- /dev/null
+++ b/test/clang-rename/TemplateClassInstantiation.cpp
@@ -0,0 +1,42 @@
+template <typename T>
+class Foo { /* Test 1 */ // CHECK: class Bar { /* Test 1 */
+public:
+ T foo(T arg, T& ref, T* ptr) {
+ T value;
+ int number = 42;
+ value = (T)number;
+ value = static_cast<T>(number);
+ return value;
+ }
+ static void foo(T value) {}
+ T member;
+};
+
+template <typename T>
+void func() {
+ Foo<T> obj; /* Test 2 */ // CHECK: Bar<T> obj;
+ obj.member = T();
+ Foo<T>::foo(); // CHECK: Bar<T>::foo();
+}
+
+int main() {
+ Foo<int> i; /* Test 3 */ // CHECK: Bar<int> i;
+ i.member = 0;
+ Foo<int>::foo(0); // CHECK: Bar<int>::foo(0);
+
+ Foo<bool> b; // CHECK: Bar<bool> b;
+ b.member = false;
+ Foo<bool>::foo(false); // CHECK: Bar<bool>::foo(false);
+
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=29 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=324 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=463 -new-name=Bar %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/TemplateTypename.cpp b/test/clang-rename/TemplateTypename.cpp
new file mode 100644
index 0000000000..559ec1f9ad
--- /dev/null
+++ b/test/clang-rename/TemplateTypename.cpp
@@ -0,0 +1,24 @@
+template <typename T /* Test 1 */> // CHECK: template <typename U /* Test 1 */>
+class Foo {
+T foo(T arg, T& ref, T* /* Test 2 */ ptr) { // CHECK: U foo(U arg, U& ref, U* /* Test 2 */ ptr) {
+ T value; // CHECK: U value;
+ int number = 42;
+ value = (T)number; // CHECK: value = (U)number;
+ value = static_cast<T /* Test 3 */>(number); // CHECK: value = static_cast<U /* Test 3 */>(number);
+ return value;
+}
+
+static void foo(T value) {} // CHECK: static void foo(U value) {}
+
+T member; // CHECK: U member;
+};
+
+// Test 1.
+// RUN: clang-rename -offset=19 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=126 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=392 -new-name=U %s -- -fno-delayed-template-parsing | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'T.*' <file>
diff --git a/test/clang-rename/TemplatedClassFunction.cpp b/test/clang-rename/TemplatedClassFunction.cpp
new file mode 100644
index 0000000000..1f5b0b52ba
--- /dev/null
+++ b/test/clang-rename/TemplatedClassFunction.cpp
@@ -0,0 +1,22 @@
+template <typename T>
+class A {
+public:
+ void foo() /* Test 1 */ {} // CHECK: void bar() /* Test 1 */ {}
+};
+
+int main(int argc, char **argv) {
+ A<int> a;
+ a.foo(); /* Test 2 */ // CHECK: a.bar() /* Test 2 */
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+//
+// Currently unsupported test.
+// XFAIL: *
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'foo.*' <file>
diff --git a/test/clang-rename/UserDefinedConversion.cpp b/test/clang-rename/UserDefinedConversion.cpp
new file mode 100644
index 0000000000..60f251ab44
--- /dev/null
+++ b/test/clang-rename/UserDefinedConversion.cpp
@@ -0,0 +1,26 @@
+class Foo { /* Test 1 */ // CHECK: class Bar {
+public:
+ Foo() {} // CHECK: Bar() {}
+};
+
+class Baz {
+public:
+ operator Foo() /* Test 2 */ const { // CHECK: operator Bar() /* Test 2 */ const {
+ Foo foo; // CHECK: Bar foo;
+ return foo;
+ }
+};
+
+int main() {
+ Baz boo;
+ Foo foo = static_cast<Foo>(boo); // CHECK: Bar foo = static_cast<Bar>(boo);
+ return 0;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=164 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/Variable.cpp b/test/clang-rename/Variable.cpp
new file mode 100644
index 0000000000..d7e670fb43
--- /dev/null
+++ b/test/clang-rename/Variable.cpp
@@ -0,0 +1,33 @@
+#define NAMESPACE namespace A
+NAMESPACE {
+int Foo; /* Test 1 */ // CHECK: int Bar;
+}
+int Foo; // CHECK: int Foo;
+int Qux = Foo; // CHECK: int Qux = Foo;
+int Baz = A::Foo; /* Test 2 */ // CHECK: Baz = A::Bar;
+void fun() {
+ struct {
+ int Foo; // CHECK: int Foo;
+ } b = {100};
+ int Foo = 100; // CHECK: int Foo = 100;
+ Baz = Foo; // CHECK: Baz = Foo;
+ {
+ extern int Foo; // CHECK: extern int Foo;
+ Baz = Foo; // CHECK: Baz = Foo;
+ Foo = A::Foo /* Test 3 */ + Baz; // CHECK: Foo = A::Bar /* Test 3 */ + Baz;
+ A::Foo /* Test 4 */ = b.Foo; // CHECK: A::Bar /* Test 4 */ = b.Foo;
+ }
+ Foo = b.Foo; // Foo = b.Foo;
+}
+
+// Test 1.
+// RUN: clang-rename -offset=46 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=234 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=641 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=716 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/VariableMacro.cpp b/test/clang-rename/VariableMacro.cpp
new file mode 100644
index 0000000000..622e825d3e
--- /dev/null
+++ b/test/clang-rename/VariableMacro.cpp
@@ -0,0 +1,21 @@
+#define Baz Foo // CHECK: #define Baz Bar
+
+void foo(int value) {}
+
+void macro() {
+ int Foo; /* Test 1 */ // CHECK: int Bar;
+ Foo = 42; /* Test 2 */ // CHECK: Bar = 42;
+ Baz -= 0;
+ foo(Foo); /* Test 3 */ // CHECK: foo(Bar);
+ foo(Baz);
+}
+
+// Test 1.
+// RUN: clang-rename -offset=88 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -offset=129 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=191 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+
+// To find offsets after modifying the file, use:
+// grep -Ubo 'Foo.*' <file>
diff --git a/test/clang-rename/YAMLInput.cpp b/test/clang-rename/YAMLInput.cpp
new file mode 100644
index 0000000000..55dbc6d66a
--- /dev/null
+++ b/test/clang-rename/YAMLInput.cpp
@@ -0,0 +1,10 @@
+class Foo1 { // CHECK: class Bar1
+};
+
+class Foo2 { // CHECK: class Bar2
+};
+
+// Test 1.
+// RUN: clang-rename -input %S/Inputs/OffsetToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 2.
+// RUN: clang-rename -input %S/Inputs/QualifiedNameToNewName.yaml %s -- | sed 's,//.*,,' | FileCheck %s