55import 'package:analyzer/src/error/codes.dart' ;
66import 'package:test_reflective_loader/test_reflective_loader.dart' ;
77
8- import '../../generated/test_support.dart' ;
98import '../dart/resolution/context_collection_resolution.dart' ;
109
1110main () {
@@ -18,59 +17,90 @@ main() {
1817class ImportDeferredLibraryWithLoadFunctionTest
1918 extends PubPackageResolutionTest {
2019 test_deferredImport_withLoadLibraryFunction () async {
21- newFile ('$testPackageLibPath /lib1 .dart' , content: r'''
22- library lib1;
23- loadLibrary () {}
24- f() {} ''' );
20+ newFile ('$testPackageLibPath /a .dart' , content: r'''
21+ void loadLibrary() {}
22+ void f () {}
23+ ''' );
2524
26- newFile ('$testPackageLibPath /lib2.dart' , content: r'''
27- library root;
28- import 'lib1.dart' deferred as lib1;
29- main() { lib1.f(); }''' );
30-
31- await _resolveFile ('$testPackageLibPath /lib1.dart' );
32- await _resolveFile ('$testPackageLibPath /lib2.dart' , [
33- error (HintCode .IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION , 14 , 36 ),
25+ await assertErrorsInCode (r'''
26+ import 'a.dart' deferred as p;
27+ void main() {
28+ p.f();
29+ }
30+ ''' , [
31+ error (HintCode .IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION , 0 , 30 ),
3432 ]);
3533 }
3634
37- test_deferredImport_withoutLoadLibraryFunction () async {
38- newFile ('$testPackageLibPath /lib1.dart' , content: r'''
39- library lib1;
40- f() {}''' );
35+ test_deferredImport_withLoadLibraryFunction_hide () async {
36+ newFile ('$testPackageLibPath /a.dart' , content: r'''
37+ void loadLibrary() {}
38+ void f() {}
39+ ''' );
4140
42- newFile ('$testPackageLibPath /lib2.dart' , content: r'''
43- library root;
44- import 'lib1.dart' deferred as lib1;
45- main() { lib1.f(); }''' );
41+ await assertNoErrorsInCode (r'''
42+ import 'a.dart' deferred as p hide loadLibrary;
43+ void main() {
44+ p.f();
45+ }
46+ ''' );
47+ }
4648
47- await _resolveFile ('$testPackageLibPath /lib1.dart' );
48- await _resolveFile ('$testPackageLibPath /lib2.dart' );
49+ test_deferredImport_withLoadLibraryFunction_hide2 () async {
50+ newFile ('$testPackageLibPath /a.dart' , content: r'''
51+ void loadLibrary() {}
52+ void f() {}
53+ void f2() {}
54+ ''' );
55+
56+ await assertErrorsInCode (r'''
57+ import 'a.dart' deferred as p hide f2;
58+ void main() {
59+ p.f();
60+ }
61+ ''' , [
62+ error (HintCode .IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION , 0 , 38 ),
63+ ]);
4964 }
5065
51- test_nonDeferredImport_withLoadLibraryFunction () async {
52- newFile ('$testPackageLibPath /lib1 .dart' , content: r'''
53- library lib1;
54- loadLibrary () {}
55- f() {} ''' );
66+ test_deferredImport_withLoadLibraryFunction_show () async {
67+ newFile ('$testPackageLibPath /a .dart' , content: r'''
68+ void loadLibrary() {}
69+ void f () {}
70+ ''' );
5671
57- newFile ('$testPackageLibPath /lib2.dart' , content: r'''
58- library root;
59- import 'lib1.dart' as lib1;
60- main() { lib1.f(); }''' );
72+ await assertNoErrorsInCode (r'''
73+ import 'a.dart' deferred as p show f;
74+ void main() {
75+ p.f();
76+ }
77+ ''' );
78+ }
79+
80+ test_deferredImport_withoutLoadLibraryFunction () async {
81+ newFile ('$testPackageLibPath /a.dart' , content: r'''
82+ void f() {}
83+ ''' );
6184
62- await _resolveFile ('$testPackageLibPath /lib1.dart' );
63- await _resolveFile ('$testPackageLibPath /lib2.dart' );
85+ await assertNoErrorsInCode (r'''
86+ import 'a.dart' deferred as p;
87+ void main() {
88+ p.f();
89+ }
90+ ''' );
6491 }
6592
66- /// Resolve the file with the given [path] .
67- ///
68- /// Similar to ResolutionTest.resolveTestFile, but a custom path is supported.
69- Future <void > _resolveFile (
70- String path, [
71- List <ExpectedError > expectedErrors = const [],
72- ]) async {
73- result = await resolveFile (convertPath (path));
74- assertErrorsInResolvedUnit (result, expectedErrors);
93+ test_nonDeferredImport_withLoadLibraryFunction () async {
94+ newFile ('$testPackageLibPath /a.dart' , content: r'''
95+ void loadLibrary() {}
96+ void f() {}
97+ ''' );
98+
99+ await assertNoErrorsInCode (r'''
100+ import 'a.dart' as p;
101+ void main() {
102+ p.f();
103+ }
104+ ''' );
75105 }
76106}
0 commit comments