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

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

Issue 2240593002: Compute the linked bundle for the SDK extension. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 | « pkg/analyzer/lib/src/summary/pub_summary.dart ('k') | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:analyzer/dart/element/element.dart'; 5 import 'package:analyzer/dart/element/element.dart';
6 import 'package:analyzer/file_system/file_system.dart'; 6 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer/source/package_map_resolver.dart'; 7 import 'package:analyzer/source/package_map_resolver.dart';
8 import 'package:analyzer/src/generated/sdk.dart'; 8 import 'package:analyzer/src/generated/sdk.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
(...skipping 17 matching lines...) Expand all
28 28
29 static Map<DartSdk, PackageBundle> sdkBundleMap = <DartSdk, PackageBundle>{}; 29 static Map<DartSdk, PackageBundle> sdkBundleMap = <DartSdk, PackageBundle>{};
30 30
31 PubSummaryManager manager; 31 PubSummaryManager manager;
32 32
33 void setUp() { 33 void setUp() {
34 super.setUp(); 34 super.setUp();
35 manager = new PubSummaryManager(resourceProvider, '_.temp'); 35 manager = new PubSummaryManager(resourceProvider, '_.temp');
36 } 36 }
37 37
38 test_computeSdkExtension() async {
39 // Create package files.
40 resourceProvider.newFile(
41 '$CACHE/aaa/lib/a.dart',
42 '''
43 class A {}
44 ''');
45 resourceProvider.newFile(
46 '$CACHE/aaa/sdk_ext/extA.dart',
47 '''
48 library test.a;
49 import 'dart:async';
50 part 'src/p1.dart';
51 part 'src/p2.dart';
52 class ExtA {}
53 int V0;
54 ''');
55 resourceProvider.newFile(
56 '$CACHE/aaa/sdk_ext/src/p1.dart',
57 '''
58 part of test.a;
59 class ExtAA {}
60 double V1;
61 ''');
62 resourceProvider.newFile(
63 '$CACHE/aaa/sdk_ext/src/p2.dart',
64 '''
65 part of test.a;
66 class ExtAB {}
67 Future V2;
68 ''');
69 resourceProvider.newFile(
70 '$CACHE/aaa/lib/_sdkext',
71 '''
72 {
73 "dart:aaa.internal": "../sdk_ext/extA.dart"
74 }
75 ''');
76 resourceProvider.newFile(
77 '$CACHE/bbb/lib/b.dart',
78 '''
79 class B {}
80 ''');
81
82 // Configure packages resolution.
83 Folder libFolderA = resourceProvider.newFolder('$CACHE/aaa/lib');
84 Folder libFolderB = resourceProvider.newFolder('$CACHE/bbb/lib');
85 context.sourceFactory = new SourceFactory(<UriResolver>[
86 sdkResolver,
87 resourceResolver,
88 new PackageMapUriResolver(resourceProvider, {
89 'aaa': [libFolderA],
90 'bbb': [libFolderB],
91 })
92 ]);
93
94 PackageBundle sdkBundle = getSdkBundle(sdk);
95 PackageBundle bundle = manager.computeSdkExtension(context, sdkBundle);
96 expect(bundle, isNotNull);
97 expect(bundle.linkedLibraryUris, ['dart:aaa.internal']);
98 expect(bundle.unlinkedUnitUris, [
99 'dart:aaa.internal',
100 'dart:aaa.internal/src/p1.dart',
101 'dart:aaa.internal/src/p2.dart'
102 ]);
103 expect(bundle.unlinkedUnits, hasLength(3));
104 expect(bundle.unlinkedUnits[0].classes.map((c) => c.name), ['ExtA']);
105 expect(bundle.unlinkedUnits[1].classes.map((c) => c.name), ['ExtAA']);
106 expect(bundle.unlinkedUnits[2].classes.map((c) => c.name), ['ExtAB']);
107 // The library is linked.
108 expect(bundle.linkedLibraries, hasLength(1));
109 LinkedLibrary linkedLibrary = bundle.linkedLibraries[0];
110 // V0 is linked
111 {
112 UnlinkedUnit unlinkedUnit = bundle.unlinkedUnits[0];
113 LinkedUnit linkedUnit = linkedLibrary.units[0];
114 expect(unlinkedUnit.variables, hasLength(1));
115 UnlinkedVariable variable = unlinkedUnit.variables[0];
116 expect(variable.name, 'V0');
117 int typeRef = variable.type.reference;
118 expect(unlinkedUnit.references[typeRef].name, 'int');
119 LinkedReference linkedReference = linkedUnit.references[typeRef];
120 expect(linkedLibrary.dependencies[linkedReference.dependency].uri,
121 'dart:core');
122 }
123 // V1 is linked
124 {
125 UnlinkedUnit unlinkedUnit = bundle.unlinkedUnits[1];
126 LinkedUnit linkedUnit = linkedLibrary.units[1];
127 expect(unlinkedUnit.variables, hasLength(1));
128 UnlinkedVariable variable = unlinkedUnit.variables[0];
129 expect(variable.name, 'V1');
130 int typeRef = variable.type.reference;
131 expect(unlinkedUnit.references[typeRef].name, 'double');
132 LinkedReference linkedReference = linkedUnit.references[typeRef];
133 expect(linkedLibrary.dependencies[linkedReference.dependency].uri,
134 'dart:core');
135 }
136 // V2 is linked
137 {
138 UnlinkedUnit unlinkedUnit = bundle.unlinkedUnits[2];
139 LinkedUnit linkedUnit = linkedLibrary.units[2];
140 expect(unlinkedUnit.variables, hasLength(1));
141 UnlinkedVariable variable = unlinkedUnit.variables[0];
142 expect(variable.name, 'V2');
143 int typeRef = variable.type.reference;
144 expect(unlinkedUnit.references[typeRef].name, 'Future');
145 LinkedReference linkedReference = linkedUnit.references[typeRef];
146 expect(linkedLibrary.dependencies[linkedReference.dependency].uri,
147 'dart:async');
148 }
149 }
150
38 test_getLinkedBundles_hasCycle() async { 151 test_getLinkedBundles_hasCycle() async {
39 resourceProvider.newFile( 152 resourceProvider.newFile(
40 '$CACHE/aaa/lib/a.dart', 153 '$CACHE/aaa/lib/a.dart',
41 ''' 154 '''
42 import 'package:bbb/b.dart'; 155 import 'package:bbb/b.dart';
43 class A {} 156 class A {}
44 int a1; 157 int a1;
45 B a2; 158 B a2;
46 '''); 159 ''');
47 resourceProvider.newFile( 160 resourceProvider.newFile(
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 }); 720 });
608 } 721 }
609 722
610 static PackageBundle _getBundleByPackageName( 723 static PackageBundle _getBundleByPackageName(
611 Map<PubPackage, PackageBundle> bundles, String name) { 724 Map<PubPackage, PackageBundle> bundles, String name) {
612 PubPackage package = 725 PubPackage package =
613 bundles.keys.singleWhere((package) => package.name == name); 726 bundles.keys.singleWhere((package) => package.name == name);
614 return bundles[package]; 727 return bundles[package];
615 } 728 }
616 } 729 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/pub_summary.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698