OLD | NEW |
---|---|
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 analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 15 matching lines...) Expand all Loading... | |
26 import 'package:analyzer/src/generated/resolver.dart'; | 26 import 'package:analyzer/src/generated/resolver.dart'; |
27 import 'package:analyzer/src/generated/sdk.dart'; | 27 import 'package:analyzer/src/generated/sdk.dart'; |
28 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 28 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
29 import 'package:analyzer/src/generated/source_io.dart'; | 29 import 'package:analyzer/src/generated/source_io.dart'; |
30 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 30 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
31 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 31 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
32 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 32 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
33 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 33 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
34 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 34 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
35 import 'package:analyzer/src/generated/utilities_dart.dart'; | 35 import 'package:analyzer/src/generated/utilities_dart.dart'; |
36 import 'package:analyzer/src/string_source.dart'; | |
36 import 'package:unittest/unittest.dart'; | 37 import 'package:unittest/unittest.dart'; |
37 | 38 |
38 import '../reflective_tests.dart'; | 39 import '../reflective_tests.dart'; |
39 import '../utils.dart'; | 40 import '../utils.dart'; |
40 import 'test_support.dart'; | 41 import 'test_support.dart'; |
41 | 42 |
42 main() { | 43 main() { |
43 initializeTestEnvironment(); | 44 initializeTestEnvironment(); |
44 runReflectiveTests(AnalysisDeltaTest); | 45 runReflectiveTests(AnalysisDeltaTest); |
45 runReflectiveTests(ChangeSetTest); | 46 runReflectiveTests(ChangeSetTest); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 * Create an analysis context that uses the given [options] and has a fake | 94 * Create an analysis context that uses the given [options] and has a fake |
94 * core library already resolved. Return the context that was created. | 95 * core library already resolved. Return the context that was created. |
95 */ | 96 */ |
96 static InternalAnalysisContext contextWithCoreAndOptions( | 97 static InternalAnalysisContext contextWithCoreAndOptions( |
97 AnalysisOptions options) { | 98 AnalysisOptions options) { |
98 AnalysisContextForTests context = new AnalysisContextForTests(); | 99 AnalysisContextForTests context = new AnalysisContextForTests(); |
99 context._internalSetAnalysisOptions(options); | 100 context._internalSetAnalysisOptions(options); |
100 return initContextWithCore(context); | 101 return initContextWithCore(context); |
101 } | 102 } |
102 | 103 |
104 static InternalAnalysisContext contextWithCoreAndPackages( | |
105 Map<String, String> packages) { | |
106 AnalysisContextForTests context = new AnalysisContextForTests(); | |
107 return initContextWithCore(context, new TestPackageUriResolver(packages)); | |
108 } | |
109 | |
103 /** | 110 /** |
104 * Initialize the given analysis context with a fake core library already reso lved. | 111 * Initialize the given analysis context with a fake core library already reso lved. |
105 * | 112 * |
106 * @param context the context to be initialized (not `null`) | 113 * @param context the context to be initialized (not `null`) |
107 * @return the analysis context that was created | 114 * @return the analysis context that was created |
108 */ | 115 */ |
109 static InternalAnalysisContext initContextWithCore( | 116 static InternalAnalysisContext initContextWithCore( |
110 InternalAnalysisContext context) { | 117 InternalAnalysisContext context, |
118 [UriResolver contributedResolver]) { | |
111 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( | 119 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( |
112 new JavaFile("/fake/sdk"), | 120 new JavaFile("/fake/sdk"), |
113 enableAsync: context.analysisOptions.enableAsync); | 121 enableAsync: context.analysisOptions.enableAsync); |
114 SourceFactory sourceFactory = | 122 List<UriResolver> resolvers = <UriResolver>[ |
115 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); | 123 new DartUriResolver(sdk), |
124 new FileUriResolver() | |
125 ]; | |
126 if (contributedResolver != null) { | |
127 resolvers.add(contributedResolver); | |
128 } | |
129 SourceFactory sourceFactory = new SourceFactory(resolvers); | |
116 context.sourceFactory = sourceFactory; | 130 context.sourceFactory = sourceFactory; |
117 AnalysisContext coreContext = sdk.context; | 131 AnalysisContext coreContext = sdk.context; |
118 (coreContext.analysisOptions as AnalysisOptionsImpl).strongMode = | 132 (coreContext.analysisOptions as AnalysisOptionsImpl).strongMode = |
119 context.analysisOptions.strongMode; | 133 context.analysisOptions.strongMode; |
120 // | 134 // |
121 // dart:core | 135 // dart:core |
122 // | 136 // |
123 TestTypeProvider provider = new TestTypeProvider(); | 137 TestTypeProvider provider = new TestTypeProvider(); |
124 CompilationUnitElementImpl coreUnit = | 138 CompilationUnitElementImpl coreUnit = |
125 new CompilationUnitElementImpl("core.dart"); | 139 new CompilationUnitElementImpl("core.dart"); |
(...skipping 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2460 r''' | 2474 r''' |
2461 library lib2; | 2475 library lib2; |
2462 class B {}'''); | 2476 class B {}'''); |
2463 computeLibrarySourceErrors(source); | 2477 computeLibrarySourceErrors(source); |
2464 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 2478 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
2465 assertNoErrors(source2); | 2479 assertNoErrors(source2); |
2466 assertNoErrors(source3); | 2480 assertNoErrors(source3); |
2467 verify([source, source2, source3]); | 2481 verify([source, source2, source3]); |
2468 } | 2482 } |
2469 | 2483 |
2484 @override | |
2485 void reset() { | |
2486 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages({ | |
2487 'package:meta/meta.dart': r''' | |
2488 library meta; | |
2489 | |
2490 const _Protected protected = const _Protected(); | |
2491 | |
2492 class _Protected { | |
2493 const _Protected(); | |
2494 } | |
2495 ''' | |
2496 }); | |
2497 } | |
2498 | |
2470 void test_argumentTypeNotAssignable_functionType() { | 2499 void test_argumentTypeNotAssignable_functionType() { |
2471 Source source = addSource(r''' | 2500 Source source = addSource(r''' |
2472 m() { | 2501 m() { |
2473 var a = new A(); | 2502 var a = new A(); |
2474 a.n(() => 0); | 2503 a.n(() => 0); |
2475 } | 2504 } |
2476 class A { | 2505 class A { |
2477 n(void f(int i)) {} | 2506 n(void f(int i)) {} |
2478 }'''); | 2507 }'''); |
2479 computeLibrarySourceErrors(source); | 2508 computeLibrarySourceErrors(source); |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3542 } | 3571 } |
3543 class B extends A { | 3572 class B extends A { |
3544 @override | 3573 @override |
3545 set m(int x) {} | 3574 set m(int x) {} |
3546 }'''); | 3575 }'''); |
3547 computeLibrarySourceErrors(source); | 3576 computeLibrarySourceErrors(source); |
3548 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); | 3577 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); |
3549 verify([source]); | 3578 verify([source]); |
3550 } | 3579 } |
3551 | 3580 |
3581 void test_protected_method_call_1() { | |
3582 Source source = addSource(r''' | |
3583 import 'package:meta/meta.dart'; | |
3584 class A { | |
3585 @protected | |
3586 void a(){ } | |
3587 } | |
3588 main() { | |
3589 new A().a(); | |
3590 }'''); | |
3591 computeLibrarySourceErrors(source); | |
3592 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); | |
3593 verify([source]); | |
3594 } | |
3595 | |
3596 void test_protected_method_call_2() { | |
3597 Source source = addSource(r''' | |
3598 import 'package:meta/meta.dart'; | |
3599 class A { | |
3600 @protected | |
3601 void a(){ } | |
3602 } | |
3603 class B { | |
3604 void b() => new A().a(); | |
3605 }'''); | |
3606 computeLibrarySourceErrors(source); | |
3607 assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]); | |
3608 verify([source]); | |
3609 } | |
3610 | |
3611 void test_protected_method_call_OK() { | |
3612 Source source = addSource(r''' | |
3613 import 'package:meta/meta.dart'; | |
3614 class A { | |
3615 @protected | |
3616 void a(){ } | |
3617 } | |
3618 class B extends A { | |
Brian Wilkerson
2016/02/23 17:45:56
We should test "with" and "implements" relationshi
pquitslund
2016/02/23 22:59:07
Done.
| |
3619 void b() => a(); | |
3620 }'''); | |
3621 computeLibrarySourceErrors(source); | |
3622 assertErrors(source, []); | |
3623 verify([source]); | |
3624 } | |
3625 | |
3552 void test_typeCheck_type_is_Null() { | 3626 void test_typeCheck_type_is_Null() { |
3553 Source source = addSource(r''' | 3627 Source source = addSource(r''' |
3554 m(i) { | 3628 m(i) { |
3555 bool b = i is Null; | 3629 bool b = i is Null; |
3556 }'''); | 3630 }'''); |
3557 computeLibrarySourceErrors(source); | 3631 computeLibrarySourceErrors(source); |
3558 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); | 3632 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); |
3559 verify([source]); | 3633 verify([source]); |
3560 } | 3634 } |
3561 | 3635 |
(...skipping 10841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14403 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); | 14477 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
14404 _definingCompilationUnit.types = <ClassElement>[classA, classB]; | 14478 _definingCompilationUnit.types = <ClassElement>[classA, classB]; |
14405 HashSet<ClassElement> subtypesOfA = | 14479 HashSet<ClassElement> subtypesOfA = |
14406 _subtypeManager.computeAllSubtypes(classA); | 14480 _subtypeManager.computeAllSubtypes(classA); |
14407 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 14481 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
14408 expect(subtypesOfA, hasLength(1)); | 14482 expect(subtypesOfA, hasLength(1)); |
14409 expect(arraySubtypesOfA, unorderedEquals([classB])); | 14483 expect(arraySubtypesOfA, unorderedEquals([classB])); |
14410 } | 14484 } |
14411 } | 14485 } |
14412 | 14486 |
14487 class TestPackageUriResolver extends UriResolver { | |
14488 Map<Uri, Source> sourceMap = new HashMap<Uri, Source>(); | |
14489 | |
14490 TestPackageUriResolver(Map<String, String> map) { | |
14491 map.forEach((String uri, String contents) { | |
14492 sourceMap[Uri.parse(uri)] = | |
14493 new StringSource(contents, '/test_pkg_source.dart'); | |
14494 }); | |
14495 } | |
14496 | |
14497 @override | |
14498 Source resolveAbsolute(Uri uri, [Uri actualUri]) => sourceMap[uri]; | |
14499 | |
14500 @override | |
14501 Uri restoreAbsolute(Source source) => throw new UnimplementedError(); | |
14502 } | |
14503 | |
14413 @reflectiveTest | 14504 @reflectiveTest |
14414 class TypeOverrideManagerTest extends EngineTestCase { | 14505 class TypeOverrideManagerTest extends EngineTestCase { |
14415 void test_exitScope_noScopes() { | 14506 void test_exitScope_noScopes() { |
14416 TypeOverrideManager manager = new TypeOverrideManager(); | 14507 TypeOverrideManager manager = new TypeOverrideManager(); |
14417 try { | 14508 try { |
14418 manager.exitScope(); | 14509 manager.exitScope(); |
14419 fail("Expected IllegalStateException"); | 14510 fail("Expected IllegalStateException"); |
14420 } on IllegalStateException { | 14511 } on IllegalStateException { |
14421 // Expected | 14512 // Expected |
14422 } | 14513 } |
(...skipping 2620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17043 | 17134 |
17044 void _resolveTestUnit(String code) { | 17135 void _resolveTestUnit(String code) { |
17045 testCode = code; | 17136 testCode = code; |
17046 testSource = addSource(testCode); | 17137 testSource = addSource(testCode); |
17047 LibraryElement library = resolve2(testSource); | 17138 LibraryElement library = resolve2(testSource); |
17048 assertNoErrors(testSource); | 17139 assertNoErrors(testSource); |
17049 verify([testSource]); | 17140 verify([testSource]); |
17050 testUnit = resolveCompilationUnit(testSource, library); | 17141 testUnit = resolveCompilationUnit(testSource, library); |
17051 } | 17142 } |
17052 } | 17143 } |
OLD | NEW |