Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 738183002: Tests for matching classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.incremental_resolver_test; 5 library engine.incremental_resolver_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/incremental_resolver.dart'; 10 import 'package:analyzer/src/generated/incremental_resolver.dart';
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 void test_compilationUnitMatches_true_same() { 66 void test_compilationUnitMatches_true_same() {
67 String content = r''' 67 String content = r'''
68 class C { 68 class C {
69 int m(int p) { 69 int m(int p) {
70 return p + p; 70 return p + p;
71 } 71 }
72 }'''; 72 }''';
73 _assertCompilationUnitMatches(true, content, content); 73 _assertCompilationUnitMatches(true, content, content);
74 } 74 }
75 75
76 void test_false_class_list_add() {
77 _assertCompilationUnitMatches(false, r'''
78 class A {}
79 class B {}
80 ''', r'''
81 class A {}
82 class B {}
83 class C {}
84 ''');
85 }
86
87 void test_false_class_list_remove() {
88 _assertCompilationUnitMatches(false, r'''
89 class A {}
90 class B {}
91 class C {}
92 ''', r'''
93 class A {}
94 class B {}
95 ''');
96 }
97
98 void test_false_extendsClause_add() {
99 _assertCompilationUnitMatches(false, r'''
100 class A {}
101 class B {}
102 ''', r'''
103 class A {}
104 class B extends A {}
105 ''');
106 }
107
108 void test_false_extendsClause_different() {
109 _assertCompilationUnitMatches(false, r'''
110 class A {}
111 class B {}
112 class C extends A {}
113 ''', r'''
114 class A {}
115 class B {}
116 class C extends B {}
117 ''');
118 }
119
120 void test_false_extendsClause_remove() {
121 _assertCompilationUnitMatches(false, r'''
122 class A {}
123 class B extends A{}
124 ''', r'''
125 class A {}
126 class B {}
127 ''');
128 }
129
130 void test_false_implementsClause_add() {
131 _assertCompilationUnitMatches(false, r'''
132 class A {}
133 class B {}
134 ''', r'''
135 class A {}
136 class B implements A {}
137 ''');
138 }
139
140 void test_false_implementsClause_remove() {
141 _assertCompilationUnitMatches(false, r'''
142 class A {}
143 class B implements A {}
144 ''', r'''
145 class A {}
146 class B {}
147 ''');
148 }
149
150 void test_false_implementsClause_reorder() {
151 _assertCompilationUnitMatches(false, r'''
152 class A {}
153 class B {}
154 class C implements A, B {}
155 ''', r'''
156 class A {}
157 class B {}
158 class C implements B, A {}
159 ''');
160 }
161
76 void test_false_topLevelVariable_list_add() { 162 void test_false_topLevelVariable_list_add() {
77 _assertCompilationUnitMatches(false, r''' 163 _assertCompilationUnitMatches(false, r'''
78 const int A = 1; 164 const int A = 1;
79 const int C = 3; 165 const int C = 3;
80 ''', r''' 166 ''', r'''
81 const int A = 1; 167 const int A = 1;
82 const int B = 2; 168 const int B = 2;
83 const int C = 3; 169 const int C = 3;
84 '''); 170 ''');
85 } 171 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 222 }
137 223
138 void test_false_topLevelVariable_type_differentArgs() { 224 void test_false_topLevelVariable_type_differentArgs() {
139 _assertCompilationUnitMatches(false, r''' 225 _assertCompilationUnitMatches(false, r'''
140 List<int> A; 226 List<int> A;
141 ''', r''' 227 ''', r'''
142 List<String> A; 228 List<String> A;
143 '''); 229 ''');
144 } 230 }
145 231
232 void test_false_withClause_add() {
233 _assertCompilationUnitMatches(false, r'''
234 class A {}
235 class B {}
236 ''', r'''
237 class A {}
238 class B extends Object with A {}
239 ''');
240 }
241
242 void test_false_withClause_remove() {
243 _assertCompilationUnitMatches(false, r'''
244 class A {}
245 class B extends Object with A {}
246 ''', r'''
247 class A {}
248 class B {}
249 ''');
250 }
251
252 void test_false_withClause_reorder() {
253 _assertCompilationUnitMatches(false, r'''
254 class A {}
255 class B {}
256 class C extends Object with A, B {}
257 ''', r'''
258 class A {}
259 class B {}
260 class C extends Object with B, A {}
261 ''');
262 }
263
146 void test_methodDeclarationMatches_false_parameter() { 264 void test_methodDeclarationMatches_false_parameter() {
147 _assertMethodMatches(false, r''' 265 _assertMethodMatches(false, r'''
148 class C { 266 class C {
149 int m(int p) { 267 int m(int p) {
150 return p + p; 268 return p + p;
151 } 269 }
152 }''', r''' 270 }''', r'''
153 class C { 271 class C {
154 int m(int p, int q) { 272 int m(int p, int q) {
155 return (p * q) + (q * p); 273 return (p * q) + (q * p);
(...skipping 18 matching lines...) Expand all
174 void test_methodDeclarationMatches_true_same() { 292 void test_methodDeclarationMatches_true_same() {
175 String content = r''' 293 String content = r'''
176 class C { 294 class C {
177 int m(int p) { 295 int m(int p) {
178 return p + p; 296 return p + p;
179 } 297 }
180 }'''; 298 }''';
181 _assertMethodMatches(true, content, content); 299 _assertMethodMatches(true, content, content);
182 } 300 }
183 301
302 void test_true_class_list_reorder() {
303 _assertCompilationUnitMatches(true, r'''
304 class A {}
305 class B {}
306 class C {}
307 ''', r'''
308 class C {}
309 class A {}
310 class B {}
311 ''');
312 }
313
314 void test_true_class_list_same() {
315 _assertCompilationUnitMatches(true, r'''
316 class A {}
317 class B {}
318 class C {}
319 ''', r'''
320 class A {}
321 class B {}
322 class C {}
323 ''');
324 }
325
326 void test_true_class_typeParameters_same() {
327 _assertCompilationUnitMatches(true, r'''
328 class A<T> {}
329 ''', r'''
330 class A<T> {}
331 ''');
332 }
333
334 void test_true_extendsClause_same() {
335 _assertCompilationUnitMatches(true, r'''
336 class A {}
337 class B extends A {}
338 ''', r'''
339 class A {}
340 class B extends A {}
341 ''');
342 }
343
344 void test_true_implementsClause_same() {
345 _assertCompilationUnitMatches(true, r'''
346 class A {}
347 class B implements A {}
348 ''', r'''
349 class A {}
350 class B implements A {}
351 ''');
352 }
353
184 void test_true_topLevelVariable_list_reorder() { 354 void test_true_topLevelVariable_list_reorder() {
185 _assertCompilationUnitMatches(true, r''' 355 _assertCompilationUnitMatches(true, r'''
186 const int A = 1; 356 const int A = 1;
187 const int B = 2; 357 const int B = 2;
188 const int C = 3; 358 const int C = 3;
189 ''', r''' 359 ''', r'''
190 const int C = 3; 360 const int C = 3;
191 const int A = 1; 361 const int A = 1;
192 const int B = 2; 362 const int B = 2;
193 '''); 363 ''');
(...skipping 12 matching lines...) Expand all
206 } 376 }
207 377
208 void test_true_topLevelVariable_type_sameArgs() { 378 void test_true_topLevelVariable_type_sameArgs() {
209 _assertCompilationUnitMatches(true, r''' 379 _assertCompilationUnitMatches(true, r'''
210 Map<int, String> A; 380 Map<int, String> A;
211 ''', r''' 381 ''', r'''
212 Map<int, String> A; 382 Map<int, String> A;
213 '''); 383 ''');
214 } 384 }
215 385
386 void test_true_withClause_same() {
387 _assertCompilationUnitMatches(true, r'''
388 class A {}
389 class B extends Object with A {}
390 ''', r'''
391 class A {}
392 class B extends Object with A {}
393 ''');
394 }
395
216 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, 396 void _assertCompilationUnitMatches(bool expectMatch, String oldContent,
217 String newContent) { 397 String newContent) {
218 Source source = addSource(oldContent); 398 Source source = addSource(oldContent);
219 LibraryElement library = resolve(source); 399 LibraryElement library = resolve(source);
220 CompilationUnit oldUnit = resolveCompilationUnit(source, library); 400 CompilationUnit oldUnit = resolveCompilationUnit(source, library);
221 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); 401 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent);
222 DeclarationMatcher matcher = new DeclarationMatcher(); 402 DeclarationMatcher matcher = new DeclarationMatcher();
223 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); 403 expect(matcher.matches(newUnit, oldUnit.element), expectMatch);
224 } 404 }
225 405
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 AstFactory.formalParameterList()); 707 AstFactory.formalParameterList());
528 classNode.members.add(methodNode); 708 classNode.members.add(methodNode);
529 MethodElement methodElement = 709 MethodElement methodElement =
530 ElementFactory.methodElement(methodName, null); 710 ElementFactory.methodElement(methodName, null);
531 methodNode.name.staticElement = methodElement; 711 methodNode.name.staticElement = methodElement;
532 (classNode.element as ClassElementImpl).methods = 712 (classNode.element as ClassElementImpl).methods =
533 <MethodElement>[methodElement]; 713 <MethodElement>[methodElement];
534 return methodNode; 714 return methodNode;
535 } 715 }
536 } 716 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698