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

Side by Side Diff: pkg/front_end/test/src/base/libraries_specification_test.dart

Issue 2993113003: Revert "Switch FE to use the libraries.json format." (Closed)
Patch Set: Created 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:front_end/src/base/libraries_specification.dart';
6 import 'package:test/test.dart';
7
8 main() {
9 group('parse', () {
10 test('top-level must be a map', () async {
11 var jsonString = '[]';
12 expect(
13 () => LibrariesSpecification.parse(
14 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
15 throwsA((e) => e is LibrariesSpecificationException));
16 jsonString = '""';
17 expect(
18 () => LibrariesSpecification.parse(
19 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
20 throwsA((e) => e is LibrariesSpecificationException));
21 });
22
23 test('target entry must be a map', () async {
24 var jsonString = '{"vm" : []}';
25 expect(
26 () => LibrariesSpecification.parse(
27 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
28 throwsA((e) => e is LibrariesSpecificationException));
29 jsonString = '{"vm" : ""}';
30 expect(
31 () => LibrariesSpecification.parse(
32 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
33 throwsA((e) => e is LibrariesSpecificationException));
34 });
35
36 test('library entry must exist', () async {
37 var jsonString = '{"vm" : {}}';
38 expect(
39 () => LibrariesSpecification.parse(
40 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
41 throwsA((e) => e is LibrariesSpecificationException));
42 });
43
44 test('library entry must be a map', () async {
45 var jsonString = '{"vm" : {"libraries": []}}';
46 expect(
47 () => LibrariesSpecification.parse(
48 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
49 throwsA((e) => e is LibrariesSpecificationException));
50 });
51
52 test('uri must be a string', () async {
53 var jsonString = '{"vm" : {"libraries": {"core": {"uri": 3}}}';
54 expect(
55 () => LibrariesSpecification.parse(
56 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
57 throwsA((e) => e is LibrariesSpecificationException));
58 });
59
60 test('patches must be a string or list of string', () async {
61 var jsonString = '''
62 {
63 "none": {
64 "libraries": {
65 "c" : {
66 "uri": "c/main.dart",
67 "patches": 3
68 }
69 }
70 }
71 }
72 ''';
73 expect(
74 () => LibrariesSpecification.parse(
75 Uri.parse('org-dartlang-custom:///f.json'), jsonString),
76 throwsA((e) => e is LibrariesSpecificationException));
77
78 jsonString = '''
79 {
80 "none": {
81 "libraries": {
82 "c" : {
83 "uri": "c/main.dart",
84 "patches": "a.dart"
85 }
86 }
87 }
88 }
89 ''';
90 var spec = LibrariesSpecification.parse(
91 Uri.parse('org-dartlang-custom:///f.json'), jsonString);
92 expect(spec.specificationFor("none").libraryInfoFor("c").patches.first,
93 Uri.parse('org-dartlang-custom:///a.dart'));
94
95 jsonString = '''
96 {
97 "none": {
98 "libraries": {
99 "c" : {
100 "uri": "c/main.dart",
101 "patches": ["a.dart"]
102 }
103 }
104 }
105 }
106 ''';
107 spec = LibrariesSpecification.parse(
108 Uri.parse('org-dartlang-custom:///f.json'), jsonString);
109 expect(spec.specificationFor("none").libraryInfoFor("c").patches.first,
110 Uri.parse('org-dartlang-custom:///a.dart'));
111 });
112
113 test('patches are optional in the format', () async {
114 var jsonString = '''
115 { "none": { "libraries": {"c" : { "uri": "c/main.dart" }}}}
116 ''';
117 var spec = LibrariesSpecification.parse(
118 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
119 expect(spec, isNotNull);
120 expect(
121 spec.specificationFor('none').libraryInfoFor('c').patches, isEmpty);
122 });
123
124 test('library paths are resolved from spec uri', () async {
125 var jsonString = '''
126 { "none": { "libraries": {"c" : { "uri": "c/main.dart" }}}}
127 ''';
128
129 var spec = LibrariesSpecification.parse(
130 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
131 expect(spec.specificationFor('none').libraryInfoFor('c').uri,
132 Uri.parse('org-dartlang-custom:///one/two/c/main.dart'));
133 });
134
135 test('patches paths are resolved from spec uri', () async {
136 var jsonString = '''
137 {
138 "none": {
139 "libraries": {
140 "c" : {
141 "uri": "c/main.dart",
142 "patches": [
143 "../a/p1.dart",
144 "../a/p2.dart"
145 ]
146 }
147 }
148 }
149 }
150 ''';
151
152 var spec = LibrariesSpecification.parse(
153 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
154 expect(spec.specificationFor('none').libraryInfoFor('c').patches[0],
155 Uri.parse('org-dartlang-custom:///one/a/p1.dart'));
156 expect(spec.specificationFor('none').libraryInfoFor('c').patches[1],
157 Uri.parse('org-dartlang-custom:///one/a/p2.dart'));
158 });
159
160 test('multiple targets are supported', () async {
161 var jsonString = '''
162 {
163 "vm": {
164 "libraries": {
165 "foo" : {
166 "uri": "a/main.dart",
167 "patches": [
168 "a/p1.dart",
169 "a/p2.dart"
170 ]
171 },
172 "bar" : {
173 "uri": "b/main.dart",
174 "patches": [
175 "b/p3.dart"
176 ]
177 }
178 }
179 },
180 "none": {
181 "libraries": {
182 "c" : {
183 "uri": "c/main.dart"
184 }
185 }
186 }
187 }
188 ''';
189
190 var spec = LibrariesSpecification.parse(
191 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
192
193 expect(spec.specificationFor('vm').libraryInfoFor('foo').uri,
194 Uri.parse('org-dartlang-custom:///one/two/a/main.dart'));
195 expect(spec.specificationFor('vm').libraryInfoFor('bar').uri,
196 Uri.parse('org-dartlang-custom:///one/two/b/main.dart'));
197 expect(spec.specificationFor('none').libraryInfoFor('c').uri,
198 Uri.parse('org-dartlang-custom:///one/two/c/main.dart'));
199 });
200 });
201
202 group('toJson', () {
203 test('serialization produces same data that was parsed', () async {
204 var jsonString = '''
205 {
206 "vm": {
207 "libraries": {
208 "foo" : {
209 "uri": "a/main.dart",
210 "patches": [
211 "a/p1.dart",
212 "a/p2.dart"
213 ]
214 },
215 "bar" : {
216 "uri": "b/main.dart",
217 "patches": [
218 "b/p3.dart"
219 ]
220 }
221 }
222 },
223 "none": {
224 "libraries": {
225 "c" : {
226 "uri": "c/main.dart",
227 "patches": []
228 }
229 }
230 }
231 }
232 ''';
233
234 var spec = LibrariesSpecification.parse(
235 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
236 var newJson =
237 spec.toJsonString(Uri.parse('org-dartlang-custom:///one/two/g.json'));
238 expect(jsonString.replaceAll(new RegExp('\\s'), ''), newJson);
239 });
240
241 test('serialization can adapt to new file location', () async {
242 var jsonString = '''
243 {
244 "vm": {
245 "libraries": {
246 "foo" : {
247 "uri": "a/main.dart",
248 "patches": [
249 "a/p1.dart",
250 "a/p2.dart"
251 ]
252 },
253 "bar" : {
254 "uri": "b/main.dart",
255 "patches": [
256 "b/p3.dart"
257 ]
258 }
259 }
260 },
261 "none": {
262 "libraries": {
263 "c" : {
264 "uri": "c/main.dart"
265 }
266 }
267 }
268 }
269 ''';
270
271 var spec = LibrariesSpecification.parse(
272 Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
273 var newJson =
274 spec.toJsonString(Uri.parse('org-dartlang-custom:///one/g.json'));
275
276 var expected = '''
277 {
278 "vm": {
279 "libraries": {
280 "foo" : {
281 "uri": "two/a/main.dart",
282 "patches": [
283 "two/a/p1.dart",
284 "two/a/p2.dart"
285 ]
286 },
287 "bar" : {
288 "uri": "two/b/main.dart",
289 "patches": [
290 "two/b/p3.dart"
291 ]
292 }
293 }
294 },
295 "none": {
296 "libraries": {
297 "c" : {
298 "uri": "two/c/main.dart",
299 "patches": []
300 }
301 }
302 }
303 }
304 ''';
305
306 expect(expected.replaceAll(new RegExp('\\s'), ''), newJson);
307 });
308 });
309 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/kernel_generator_test.dart ('k') | pkg/front_end/test/src/base/processed_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698