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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1687173002: Test summarization of redirected factory constructors from imported libraries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 expectedKind: ReferenceKind.constructor, 3206 expectedKind: ReferenceKind.constructor,
3207 prefixExpectations: [ 3207 prefixExpectations: [
3208 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D', 3208 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D',
3209 numTypeParameters: 2) 3209 numTypeParameters: 2)
3210 ], 3210 ],
3211 allowTypeParameters: true); 3211 allowTypeParameters: true);
3212 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1); 3212 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3213 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2); 3213 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3214 } 3214 }
3215 3215
3216 test_constructor_redirected_factory_named_imported() {
3217 addNamedSource(
3218 '/foo.dart',
3219 '''
3220 import 'test.dart';
3221 class D extends C {
3222 D.named() : super._();
3223 }
3224 ''');
3225 String text = '''
3226 import 'foo.dart';
3227 class C {
3228 factory C() = D.named;
3229 C._();
3230 }
3231 ''';
3232 UnlinkedExecutable executable =
3233 serializeClassText(text, className: 'C').executables[0];
3234 expect(executable.isRedirectedConstructor, isTrue);
3235 expect(executable.isFactory, isTrue);
3236 expect(executable.redirectedConstructorName, isEmpty);
3237 checkTypeRef(executable.redirectedConstructor, null, null, 'named',
3238 expectedKind: ReferenceKind.constructor,
3239 prefixExpectations: [
3240 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D',
3241 absoluteUri: absUri('/foo.dart'), relativeUri: 'foo.dart')
3242 ]);
3243 }
3244
3245 test_constructor_redirected_factory_named_imported_generic() {
3246 addNamedSource(
3247 '/foo.dart',
3248 '''
3249 import 'test.dart';
3250 class D<T, U> extends C<U, T> {
3251 D.named() : super._();
3252 }
3253 ''');
3254 String text = '''
3255 import 'foo.dart';
3256 class C<T, U> {
3257 factory C() = D<U, T>.named;
3258 C._();
3259 }
3260 ''';
3261 UnlinkedExecutable executable =
3262 serializeClassText(text, className: 'C').executables[0];
3263 expect(executable.isRedirectedConstructor, isTrue);
3264 expect(executable.isFactory, isTrue);
3265 expect(executable.redirectedConstructorName, isEmpty);
3266 checkTypeRef(executable.redirectedConstructor, null, null, 'named',
3267 expectedKind: ReferenceKind.constructor,
3268 prefixExpectations: [
3269 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D',
3270 numTypeParameters: 2,
3271 absoluteUri: absUri('/foo.dart'),
3272 relativeUri: 'foo.dart')
3273 ],
3274 allowTypeParameters: true);
3275 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3276 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3277 }
3278
3279 test_constructor_redirected_factory_named_prefixed() {
3280 addNamedSource(
3281 '/foo.dart',
3282 '''
3283 import 'test.dart';
3284 class D extends C {
3285 D.named() : super._();
3286 }
3287 ''');
3288 String text = '''
3289 import 'foo.dart' as foo;
3290 class C {
3291 factory C() = foo.D.named;
3292 C._();
3293 }
3294 ''';
3295 UnlinkedExecutable executable =
3296 serializeClassText(text, className: 'C').executables[0];
3297 expect(executable.isRedirectedConstructor, isTrue);
3298 expect(executable.isFactory, isTrue);
3299 expect(executable.redirectedConstructorName, isEmpty);
3300 checkTypeRef(executable.redirectedConstructor, null, null, 'named',
3301 expectedKind: ReferenceKind.constructor,
3302 prefixExpectations: [
3303 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D',
3304 absoluteUri: absUri('/foo.dart'), relativeUri: 'foo.dart'),
3305 new _PrefixExpectation(ReferenceKind.prefix, 'foo')
3306 ]);
3307 }
3308
3309 test_constructor_redirected_factory_named_prefixed_generic() {
3310 addNamedSource(
3311 '/foo.dart',
3312 '''
3313 import 'test.dart';
3314 class D<T, U> extends C<U, T> {
3315 D.named() : super._();
3316 }
3317 ''');
3318 String text = '''
3319 import 'foo.dart' as foo;
3320 class C<T, U> {
3321 factory C() = foo.D<U, T>.named;
3322 C._();
3323 }
3324 ''';
3325 UnlinkedExecutable executable =
3326 serializeClassText(text, className: 'C').executables[0];
3327 expect(executable.isRedirectedConstructor, isTrue);
3328 expect(executable.isFactory, isTrue);
3329 expect(executable.redirectedConstructorName, isEmpty);
3330 checkTypeRef(executable.redirectedConstructor, null, null, 'named',
3331 expectedKind: ReferenceKind.constructor,
3332 prefixExpectations: [
3333 new _PrefixExpectation(ReferenceKind.classOrEnum, 'D',
3334 numTypeParameters: 2,
3335 absoluteUri: absUri('/foo.dart'),
3336 relativeUri: 'foo.dart'),
3337 new _PrefixExpectation(ReferenceKind.prefix, 'foo')
3338 ],
3339 allowTypeParameters: true);
3340 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3341 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3342 }
3343
3216 test_constructor_redirected_factory_unnamed() { 3344 test_constructor_redirected_factory_unnamed() {
3217 String text = ''' 3345 String text = '''
3218 class C { 3346 class C {
3219 factory C() = D; 3347 factory C() = D;
3220 C._(); 3348 C._();
3221 } 3349 }
3222 class D extends C { 3350 class D extends C {
3223 D() : super._(); 3351 D() : super._();
3224 } 3352 }
3225 '''; 3353 ''';
(...skipping 19 matching lines...) Expand all
3245 serializeClassText(text, className: 'C').executables[0]; 3373 serializeClassText(text, className: 'C').executables[0];
3246 expect(executable.isRedirectedConstructor, isTrue); 3374 expect(executable.isRedirectedConstructor, isTrue);
3247 expect(executable.isFactory, isTrue); 3375 expect(executable.isFactory, isTrue);
3248 expect(executable.redirectedConstructorName, isEmpty); 3376 expect(executable.redirectedConstructorName, isEmpty);
3249 checkTypeRef(executable.redirectedConstructor, null, null, 'D', 3377 checkTypeRef(executable.redirectedConstructor, null, null, 'D',
3250 allowTypeParameters: true, numTypeParameters: 2); 3378 allowTypeParameters: true, numTypeParameters: 2);
3251 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1); 3379 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3252 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2); 3380 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3253 } 3381 }
3254 3382
3383 test_constructor_redirected_factory_unnamed_imported() {
3384 addNamedSource(
3385 '/foo.dart',
3386 '''
3387 import 'test.dart';
3388 class D extends C {
3389 D() : super._();
3390 }
3391 ''');
3392 String text = '''
3393 import 'foo.dart';
3394 class C {
3395 factory C() = D;
3396 C._();
3397 }
3398 ''';
3399 UnlinkedExecutable executable =
3400 serializeClassText(text, className: 'C').executables[0];
3401 expect(executable.isRedirectedConstructor, isTrue);
3402 expect(executable.isFactory, isTrue);
3403 expect(executable.redirectedConstructorName, isEmpty);
3404 checkTypeRef(
3405 executable.redirectedConstructor, absUri('/foo.dart'), 'foo.dart', 'D');
3406 }
3407
3408 test_constructor_redirected_factory_unnamed_imported_generic() {
3409 addNamedSource(
3410 '/foo.dart',
3411 '''
3412 import 'test.dart';
3413 class D<T, U> extends C<U, T> {
3414 D() : super._();
3415 }
3416 ''');
3417 String text = '''
3418 import 'foo.dart';
3419 class C<T, U> {
3420 factory C() = D<U, T>;
3421 C._();
3422 }
3423 ''';
3424 UnlinkedExecutable executable =
3425 serializeClassText(text, className: 'C').executables[0];
3426 expect(executable.isRedirectedConstructor, isTrue);
3427 expect(executable.isFactory, isTrue);
3428 expect(executable.redirectedConstructorName, isEmpty);
3429 checkTypeRef(
3430 executable.redirectedConstructor, absUri('/foo.dart'), 'foo.dart', 'D',
3431 allowTypeParameters: true, numTypeParameters: 2);
3432 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3433 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3434 }
3435
3436 test_constructor_redirected_factory_unnamed_prefixed() {
3437 addNamedSource(
3438 '/foo.dart',
3439 '''
3440 import 'test.dart';
3441 class D extends C {
3442 D() : super._();
3443 }
3444 ''');
3445 String text = '''
3446 import 'foo.dart' as foo;
3447 class C {
3448 factory C() = foo.D;
3449 C._();
3450 }
3451 ''';
3452 UnlinkedExecutable executable =
3453 serializeClassText(text, className: 'C').executables[0];
3454 expect(executable.isRedirectedConstructor, isTrue);
3455 expect(executable.isFactory, isTrue);
3456 expect(executable.redirectedConstructorName, isEmpty);
3457 checkTypeRef(
3458 executable.redirectedConstructor, absUri('/foo.dart'), 'foo.dart', 'D',
3459 expectedPrefix: 'foo');
3460 }
3461
3462 test_constructor_redirected_factory_unnamed_prefixed_generic() {
3463 addNamedSource(
3464 '/foo.dart',
3465 '''
3466 import 'test.dart';
3467 class D<T, U> extends C<U, T> {
3468 D() : super._();
3469 }
3470 ''');
3471 String text = '''
3472 import 'foo.dart' as foo;
3473 class C<T, U> {
3474 factory C() = foo.D<U, T>;
3475 C._();
3476 }
3477 ''';
3478 UnlinkedExecutable executable =
3479 serializeClassText(text, className: 'C').executables[0];
3480 expect(executable.isRedirectedConstructor, isTrue);
3481 expect(executable.isFactory, isTrue);
3482 expect(executable.redirectedConstructorName, isEmpty);
3483 checkTypeRef(
3484 executable.redirectedConstructor, absUri('/foo.dart'), 'foo.dart', 'D',
3485 allowTypeParameters: true, numTypeParameters: 2, expectedPrefix: 'foo');
3486 checkParamTypeRef(executable.redirectedConstructor.typeArguments[0], 1);
3487 checkParamTypeRef(executable.redirectedConstructor.typeArguments[1], 2);
3488 }
3489
3255 test_constructor_redirected_thisInvocation_named() { 3490 test_constructor_redirected_thisInvocation_named() {
3256 String text = ''' 3491 String text = '''
3257 class C { 3492 class C {
3258 C() : this.named(); 3493 C() : this.named();
3259 C.named(); 3494 C.named();
3260 } 3495 }
3261 '''; 3496 ''';
3262 UnlinkedExecutable executable = 3497 UnlinkedExecutable executable =
3263 serializeClassText(text, className: 'C').executables[0]; 3498 serializeClassText(text, className: 'C').executables[0];
3264 expect(executable.isRedirectedConstructor, isTrue); 3499 expect(executable.isRedirectedConstructor, isTrue);
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after
6125 final String absoluteUri; 6360 final String absoluteUri;
6126 final String relativeUri; 6361 final String relativeUri;
6127 final int numTypeParameters; 6362 final int numTypeParameters;
6128 6363
6129 _PrefixExpectation(this.kind, this.name, 6364 _PrefixExpectation(this.kind, this.name,
6130 {this.inLibraryDefiningUnit: false, 6365 {this.inLibraryDefiningUnit: false,
6131 this.absoluteUri, 6366 this.absoluteUri,
6132 this.relativeUri, 6367 this.relativeUri,
6133 this.numTypeParameters: 0}); 6368 this.numTypeParameters: 0});
6134 } 6369 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698