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.src.context.source_test; | |
6 | |
7 import 'package:analyzer/file_system/file_system.dart'; | 5 import 'package:analyzer/file_system/file_system.dart'; |
6 import 'package:analyzer/file_system/memory_file_system.dart'; | |
8 import 'package:analyzer/src/context/source.dart'; | 7 import 'package:analyzer/src/context/source.dart'; |
8 import 'package:analyzer/src/dart/sdk/sdk.dart'; | |
9 import 'package:analyzer/src/generated/java_engine_io.dart'; | |
9 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:package_config/packages.dart'; | 11 import 'package:package_config/packages.dart'; |
11 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
13 | 14 |
14 import 'abstract_context.dart'; | 15 import 'abstract_context.dart'; |
15 | 16 |
16 main() { | 17 main() { |
17 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
18 defineReflectiveTests(SourceFactoryImplTest); | 19 defineReflectiveTests(SourceFactoryImplTest); |
19 }); | 20 }); |
20 } | 21 } |
21 | 22 |
22 @reflectiveTest | 23 @reflectiveTest |
23 class SourceFactoryImplTest extends AbstractContextTest { | 24 class SourceFactoryImplTest extends AbstractContextTest { |
25 @soloTest | |
26 void test_resolveUri_coreFromPart() { | |
27 SourceFactoryImpl sourceFactory = new SourceFactoryImpl(<UriResolver>[ | |
28 new ResourceUriResolver(resourceProvider), | |
29 new DartUriResolver(_createDartSdk()) | |
30 ]); | |
31 Source coreSource = sourceFactory.forUri('dart:core'); | |
32 Source numSource = sourceFactory.resolveUri(coreSource, 'num.dart'); | |
33 expect(sourceFactory.resolveUri(numSource, 'core.dart'), coreSource); | |
scheglov
2017/06/29 20:19:24
We test functionality of DartSdk, so it would be l
Brian Wilkerson
2017/06/29 20:47:15
Done
| |
34 } | |
35 | |
24 void test_restoreUri() { | 36 void test_restoreUri() { |
25 String libPath = resourceProvider.convertPath('/pkgs/somepkg/lib/'); | 37 String libPath = resourceProvider.convertPath('/pkgs/somepkg/lib/'); |
26 Uri libUri = resourceProvider.getFolder(libPath).toUri(); | 38 Uri libUri = resourceProvider.getFolder(libPath).toUri(); |
27 Map<String, Uri> packageUriMap = <String, Uri>{'foo': libUri}; | 39 Map<String, Uri> packageUriMap = <String, Uri>{'foo': libUri}; |
28 SourceFactoryImpl sourceFactory = new SourceFactoryImpl( | 40 SourceFactoryImpl sourceFactory = new SourceFactoryImpl( |
29 <UriResolver>[new ResourceUriResolver(resourceProvider)], | 41 <UriResolver>[new ResourceUriResolver(resourceProvider)], |
30 new _MockPackages(packageUriMap), | 42 new _MockPackages(packageUriMap), |
31 ); | 43 ); |
32 Source libSource = newSource('/pkgs/somepkg/lib'); | 44 Source libSource = newSource('/pkgs/somepkg/lib'); |
33 Uri uri = sourceFactory.restoreUri(libSource); | 45 Uri uri = sourceFactory.restoreUri(libSource); |
34 try { | 46 try { |
35 expect(uri, Uri.parse('package:foo/')); | 47 expect(uri, Uri.parse('package:foo/')); |
36 } catch (e) { | 48 } catch (e) { |
37 print('=== debug info ==='); | 49 print('=== debug info ==='); |
38 print('libPath: $libPath'); | 50 print('libPath: $libPath'); |
39 print('libUri: $libUri'); | 51 print('libUri: $libUri'); |
40 print('libSource: ${libSource?.fullName}'); | 52 print('libSource: ${libSource?.fullName}'); |
41 rethrow; | 53 rethrow; |
42 } | 54 } |
43 } | 55 } |
56 | |
57 FolderBasedDartSdk _createDartSdk() { | |
58 resourceProvider = new MemoryResourceProvider(); | |
59 Folder sdkDirectory = | |
60 resourceProvider.getFolder(resourceProvider.convertPath('/sdk')); | |
61 _createFile(sdkDirectory, | |
62 ['lib', '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'], | |
63 content: _librariesFileContent()); | |
64 _createFile(sdkDirectory, ['bin', 'dart']); | |
65 _createFile(sdkDirectory, ['bin', 'dart2js']); | |
66 _createFile(sdkDirectory, ['bin', 'pub']); | |
67 _createFile(sdkDirectory, ['lib', 'async', 'async.dart']); | |
68 _createFile(sdkDirectory, ['lib', 'core', 'core.dart']); | |
69 _createFile(sdkDirectory, ['lib', 'core', 'num.dart']); | |
scheglov
2017/06/29 20:19:24
Hm... Why do we need all the rest if we use only c
| |
70 _createFile(sdkDirectory, | |
71 ['lib', 'html', 'html_common', 'html_common_dart2js.dart']); | |
72 _createFile(sdkDirectory, ['lib', 'html', 'dartium', 'html_dartium.dart']); | |
73 _createFile( | |
74 sdkDirectory, ['bin', (OSUtilities.isWindows() ? 'pub.bat' : 'pub')]); | |
75 return new FolderBasedDartSdk(resourceProvider, sdkDirectory); | |
76 } | |
77 | |
78 void _createFile(Folder directory, List<String> segments, | |
79 {String content: ''}) { | |
80 Folder parent = directory; | |
81 int last = segments.length - 1; | |
82 for (int i = 0; i < last; i++) { | |
83 parent = parent.getChildAssumingFolder(segments[i]); | |
84 } | |
85 File file = parent.getChildAssumingFile(segments[last]); | |
86 resourceProvider.newFile(file.path, content); | |
87 } | |
88 | |
89 String _librariesFileContent() => ''' | |
90 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
91 "async": const LibraryInfo( | |
92 "async/async.dart", | |
93 categories: "Client,Server", | |
94 maturity: Maturity.STABLE, | |
95 dart2jsPatchPath: "_internal/js_runtime/lib/async_patch.dart"), | |
96 | |
97 "core": const LibraryInfo( | |
98 "core/core.dart", | |
99 categories: "Client,Server,Embedded", | |
100 maturity: Maturity.STABLE, | |
101 dart2jsPatchPath: "_internal/js_runtime/lib/core_patch.dart"), | |
102 | |
103 "html": const LibraryInfo( | |
104 "html/dartium/html_dartium.dart", | |
105 categories: "Client", | |
106 maturity: Maturity.WEB_STABLE, | |
107 dart2jsPath: "html/dart2js/html_dart2js.dart"), | |
108 | |
109 "html_common": const LibraryInfo( | |
110 "html/html_common/html_common.dart", | |
111 categories: "Client", | |
112 maturity: Maturity.WEB_STABLE, | |
113 dart2jsPath: "html/html_common/html_common_dart2js.dart", | |
114 documented: false, | |
115 implementation: true), | |
116 }; | |
117 '''; | |
44 } | 118 } |
45 | 119 |
46 /** | 120 /** |
47 * An implementation of [Packages] used for testing. | 121 * An implementation of [Packages] used for testing. |
48 */ | 122 */ |
49 class _MockPackages implements Packages { | 123 class _MockPackages implements Packages { |
50 final Map<String, Uri> map; | 124 final Map<String, Uri> map; |
51 | 125 |
52 _MockPackages(this.map); | 126 _MockPackages(this.map); |
53 | 127 |
54 @override | 128 @override |
55 Iterable<String> get packages => map.keys; | 129 Iterable<String> get packages => map.keys; |
56 | 130 |
57 @override | 131 @override |
58 Map<String, Uri> asMap() => map; | 132 Map<String, Uri> asMap() => map; |
59 | 133 |
60 @override | 134 @override |
61 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { | 135 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { |
62 fail('Unexpected invocation of resolve'); | 136 fail('Unexpected invocation of resolve'); |
63 return null; | 137 return null; |
64 } | 138 } |
65 } | 139 } |
OLD | NEW |