blob: 33a191f2b9a0900fd1b60173d7e16c6ae4ea481c (
plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.refactoring;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.psi.PyCallExpression;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.refactoring.introduce.IntroduceHandler;
import com.jetbrains.python.refactoring.introduce.IntroduceOperation;
import com.jetbrains.python.refactoring.introduce.variable.PyIntroduceVariableHandler;
import java.util.Collection;
/**
* @author yole
*/
@TestDataPath("$CONTENT_ROOT/../testData/refactoring/introduceVariable/")
public class PyIntroduceVariableTest extends PyIntroduceTestCase {
public void testSimple() {
doTest();
}
public void testPy995() {
doTest();
}
public void testSkipLeadingWhitespace() { // PY-1338
doTest();
}
public void testPy2862() {
doTest();
}
public void testMultilineString() { // PY-4962
doTest();
}
public void testSuggestKeywordArgumentName() { // PY-1260
doTestSuggestions(PyExpression.class, "extra_context");
}
public void testSuggestArgumentName() { // PY-1260
doTestSuggestions(PyExpression.class, "extra_context");
}
public void testSuggestTypeName() { // PY-1336
doTestSuggestions(PyCallExpression.class, "my_class");
}
public void testSuggestStringConstantValue() { // PY-1276
doTestSuggestions(PyExpression.class, "foo_bar");
}
public void testDontSuggestBuiltinTypeNames() { // PY-4474
final Collection<String> strings = buildSuggestions(PyExpression.class);
assertTrue(strings.contains("s"));
assertFalse(strings.contains("str"));
}
public void testDontSuggestBuiltinTypeNames2() { // PY-5626
final Collection<String> strings = buildSuggestions(PyCallExpression.class);
assertTrue(strings.contains("d"));
assertFalse(strings.contains("dict"));
}
public void testSuggestNamesNotInScope() { // PY-4605
final Collection<String> strings = buildSuggestions(PyExpression.class);
assertTrue(strings.contains("myfunc1"));
assertFalse(strings.contains("myfunc"));
}
public void testIncorrectSelection() { // PY-4455
doTestCannotPerform();
}
public void testOneSidedSelection() { // PY-4456
doTestCannotPerform();
}
public void testFunctionOccurrences() { // PY-5062
doTest();
}
public void testBackslash() { // PY-6908
doTest();
}
public void testMultipartString() { // PY-6698
doTest();
}
// PY-3654
public void testSimpleSubstring() {
doTest();
}
// PY-3654
public void testLeftSubstring() {
doTest();
}
// PY-3654
public void testRightSubstring() {
doTest();
}
// PY-3654
public void testMiddleSubstring() {
doTest();
}
// PY-3654
public void testLeftQuoteSubstring() {
doTest();
}
// PY-3654
public void testSubstringInExpression() {
doTest();
}
// PY-3654
public void testSubstringInStatement() {
doTest();
}
// PY-3654
public void testTripleQuotedSubstring() {
doTest();
}
// PY-3654
public void testSubstringInExpressionStatement() {
doTest();
}
// PY-3654
public void testBytesSubstring() {
doTest();
}
// PY-3654
public void testSubstringContainsFormatChars() {
doTest();
}
// PY-3654
public void testSubstringBreaksFormatChars() {
doTestCannotPerform();
}
// PY-3654
public void testSubstringContainsEscapes() {
doTest();
}
// PY-3654
public void testSubstringBreaksEscapes() {
doTestCannotPerform();
}
// PY-3654
public void testSubstringBeforeFormatTuple() {
doTest();
}
// PY-3654
public void testSubstringInsideFormatTuple() {
doTest();
}
// PY-3654
public void testSubstringAfterFormatTuple() {
doTest();
}
// PY-3654
public void testSubstringAfterFormatTupleWithComma() {
doTest();
}
// PY-3654
public void testSubstringFromFormatDict() {
doTest();
}
// PY-3654
public void testSubstringFromFormatSingleValue() {
doTest();
}
// PY-8372
public void testSubstringBreaksNewStyleFormatChars() {
doTestCannotPerform();
}
// PY-8372
public void testSubstringNewStylePositional() {
doTest();
}
// PY-8372
public void testSubstringNewStyleAutomaticNumbering() {
doTest();
}
// PY-8372
public void testSubstringNewStyleKeywords() {
doTest();
}
public void testGeneratorParameter() {
doTest();
}
// PY-10964
public void testMultiReference() {
myFixture.configureByFile(getTestName(true) + ".py");
boolean inplaceEnabled = myFixture.getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(true);
IntroduceHandler handler = createHandler();
final IntroduceOperation operation = new IntroduceOperation(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a_");
operation.setReplaceAll(true);
handler.performAction(operation);
myFixture.checkResultByFile(getTestName(true) + ".after.py");
}
finally {
myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(inplaceEnabled);
}
}
public void testSelectionBreaksBinaryOperator() {doTest();}
private void doTestCannotPerform() {
boolean thrownExpectedException = false;
try {
doTest();
}
catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
if (e.getMessage().equals("Cannot perform refactoring using selected element(s)")) {
thrownExpectedException = true;
}
}
assertTrue(thrownExpectedException);
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/refactoring/introduceVariable";
}
protected IntroduceHandler createHandler() {
return new PyIntroduceVariableHandler();
}
}
|