File: rename-indexed-file.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (123 lines) | stat: -rw-r--r-- 5,546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Note: the run lines follow their respective tests, since line/column
// matter in this test

class Test {  // CHECK1: rename [[@LINE]]:7 -> [[@LINE]]:11
public:
  Test() { }  // CHECK1: rename [[@LINE]]:3 -> [[@LINE]]:7
  ~Test() { } // CHECK1: rename [[@LINE]]:4 -> [[@LINE]]:8

  void doSomething() { return; }
  void otherFile();
};

void foo() {
  Test test;  // CHECK1: rename [[@LINE]]:3 -> [[@LINE]]:7
  (test).doSomething();
}

Test notIndexed; // CHECK1-NOT: rename [[@LINE]]

// RUN: clang-refactor-test rename-indexed-file -name=Test -new-name=Foo -indexed-file=%s -indexed-at=4:7 -indexed-at=6:3 -indexed-at=7:4 -indexed-at=14:3 %s | FileCheck --check-prefix=CHECK1 %s

// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%S/Inputs/rename-indexed-file.cpp -indexed-at=1:6 -indexed-at=2:3 -indexed-at=3:6 %s | FileCheck --check-prefix=CHECK2 %s
// CHECK2: rename 1:6 -> 1:10
// CHECK2: rename 2:3 -> 2:7
// CHECK2: rename 3:6 -> 3:10

// A valid location with an non-identifier token shouldn't produce an occurence
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%s -indexed-at=15:3 %s | FileCheck --check-prefix=CHECK3 %s

// A invalid location shouldn't produce an occurence
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%s -indexed-at=999:1 %s | FileCheck --check-prefix=CHECK3 %s
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%s -indexed-at=0:1 %s | FileCheck --check-prefix=CHECK3 %s
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%s -indexed-at=1:0 %s | FileCheck --check-prefix=CHECK3 %s


// CHECK3: no replacements found
// CHECK3-NOT: rename

// RUN: not clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR1 %s

// CHECK-ERROR1: for the --indexed-file option: must be specified at least once!

// It should be possible to have the filename as one of the compilation arguments
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -ignore-filename-for-initiation-tu -name=Test -new-name=Foo -indexed-file=%s -indexed-at=4:7 -indexed-at=6:3 -indexed-at=7:4 -indexed-at=14:3 %s -c %s -Wall | FileCheck --check-prefix=CHECK1 %s

// -gmodules should be stripped to avoid -fmodule-format=obj in CC1 arguments:
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=Test -new-name=Foo -indexed-file=%s -indexed-at=4:7 -indexed-at=6:3 -indexed-at=7:4 -indexed-at=14:3 %s -fmodules -gmodules | FileCheck --check-prefix=CHECK1 %s

// These texual matches should be reported as comment occurrences:
// CHECK4-INIT: rename [[@LINE-46]]:7 -> [[@LINE-46]]:11
// Test
/* Test 2 Test */
/** Test+1
// Test
**/
/// Hello Test World
//! \c Test.

// CHECK4: comment [[@LINE-8]]:4 -> [[@LINE-8]]:8
// CHECK4-NEXT: comment [[@LINE-8]]:4 -> [[@LINE-8]]:8
// CHECK4-NEXT: comment [[@LINE-9]]:11 -> [[@LINE-9]]:15
// CHECK4-NEXT: documentation [[@LINE-9]]:5 -> [[@LINE-9]]:9
// CHECK4-NEXT: documentation [[@LINE-9]]:4 -> [[@LINE-9]]:8
// CHECK4-NEXT: documentation [[@LINE-8]]:11 -> [[@LINE-8]]:15
// CHECK4-NEXT: documentation [[@LINE-8]]:8 -> [[@LINE-8]]:12

// "Test"
// 'Test'
// CHECK4-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:9
// CHECK4-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:9

// CHECK4-NEXT: comment [[@LINE+1]]:55
// RUN: clang-refactor-test rename-indexed-file -name=Test -new-name=Foo -indexed-file=%s -indexed-at=4:7 %s | FileCheck --check-prefixes=CHECK4-INIT,CHECK4 %s
// We should find textual occurrences even without indexed occurrences:
// CHECK4-NEXT: comment [[@LINE+1]]:55
// RUN: clang-refactor-test rename-indexed-file -name=Test -new-name=Foo -indexed-file=%s %s | FileCheck --check-prefix=CHECK4 %s

// These ones shouldn't:
// Test2 test Testable
/// _Test
/// ATest_
const char *test = "Test";
void Test20() { }

// CHECK4-NOT: comment
// CHECK4-NOT: documentation


class MyInclude { // CHECK5: rename [[@LINE]]:7 -> [[@LINE]]:16
};

 /*comment*/ #include "MyInclude.h"
#include <clang/myinclude.h>
#import <MyInclude/ThisIsMyInclude>
// CHECK5-NEXT: filename [[@LINE-3]]:24 -> [[@LINE-3]]:33
// CHECK5-NEXT: filename [[@LINE-3]]:17 -> [[@LINE-3]]:26
// CHECK5-NEXT: filename [[@LINE-3]]:26 -> [[@LINE-3]]:35

// CHECK5-NOT: filename
#include "My Include.h"
"MyInclude.h"

// RUN: clang-refactor-test rename-indexed-file -name=MyInclude -new-name=Foo -indexed-file=%s -indexed-at=89:7 -indexed-at=include:92:1 -indexed-at=include:93:1 -indexed-at=include:94:1 -indexed-at=include:100:1 %s | FileCheck --check-prefix=CHECK5 %s

#define MACRO variable

void macroOccurrence() {
  variable;
  MACRO;
  22;
  MACRO;
}
// CHECK-MACRO: rename [[@LINE-5]]:3 -> [[@LINE-5]]:11
// CHECK-MACRO-NEXT: macro [[@LINE-5]]:3 -> [[@LINE-5]]:3
// CHECK-MACRO-NOT: macro

// RUN: clang-refactor-test rename-indexed-file -name=variable -new-name=foo -indexed-file=%s -indexed-at=108:3 -indexed-at=109:3 -indexed-at=110:3 -indexed-at=111:2 %s | FileCheck --check-prefix=CHECK-MACRO %s

struct MyType { // CHECK-MACRO-PREFIX: rename [[@LINE]]:8 -> [[@LINE]]:14
};
MyType MyTypePrefix; // CHECK-MACRO-PREFIX: macro [[@LINE]]:8 -> [[@LINE]]:8

// RUN: clang-refactor-test rename-indexed-file -name=MyType -new-name=x -indexed-file=%s -indexed-at=119:8 -indexed-at=121:8 %s | FileCheck --check-prefix=CHECK-MACRO-PREFIX %s