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

Side by Side Diff: sdk/lib/_internal/dartdoc/test/export_map_test.dart

Issue 140303009: Remove dartdoc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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:unittest/unittest.dart';
6
7 import 'dart:async' show Future;
8 import 'dart:io' show Platform;
9
10 import '../lib/src/export_map.dart';
11 import '../../../../../tests/compiler/dart2js/memory_source_file_helper.dart'
12 show MemorySourceFileProvider;
13 import '../../compiler/implementation/mirrors/source_mirrors.dart'
14 show MirrorSystem, LibraryMirror;
15 import '../../compiler/implementation/mirrors/analyze.dart'
16 as source_mirrors;
17
18 Future<MirrorSystem> mirrorSystemFor(Map<String, String> memorySourceFiles) {
19 var provider = new MemorySourceFileProvider(memorySourceFiles);
20 handler(Uri uri, int begin, int end, String message, kind) {}
21
22 var script = Uri.base.resolveUri(Platform.script);
23 var libraryRoot = script.resolve('../../../../');
24 // Read packages from 'memory:packages/'.
25 var packageRoot = Uri.parse('memory:packages/');
26
27 var libraries = <Uri>[];
28 memorySourceFiles.forEach((String path, _) {
29 if (path.startsWith('packages/')) {
30 // Analyze files from 'packages/' as packages.
31 libraries.add(new Uri(scheme: 'package', path: path.substring(9)));
32 } else {
33 libraries.add(new Uri(scheme: 'memory', path: path));
34 }
35 });
36 libraries.add(new Uri(scheme: 'dart', path: 'async'));
37 return source_mirrors.analyze(
38 libraries, libraryRoot, packageRoot, provider, handler);
39 }
40
41 Future<ExportMap> testExports(Map<String, String> sourceFiles) {
42 return mirrorSystemFor(sourceFiles).then((mirrors) {
43 libMirror = (uri) => mirrors.libraries[Uri.parse(uri)];
44 return new ExportMap(mirrors);
45 });
46 }
47
48 Function libMirror;
49
50 main() {
51 group('ExportMap', () {
52 test('with an empty library', () {
53 return testExports({'lib.dart': ''}).then((map) {
54 var lib = libMirror('memory:lib.dart');
55 var nonexistent = libMirror('memory:nonexistent.dart');
56
57 var expectedExports = {};
58 expectedExports[lib] = [];
59 expect(map.exports, equals(expectedExports));
60 expect(map.transitiveExports(lib), isEmpty);
61 expect(map.transitiveExports(nonexistent), isEmpty);
62 });
63 });
64
65 test('with one library with one export', () {
66 return testExports({
67 'a.dart': 'export "b.dart";',
68 'b.dart': ''
69 }).then((map) {
70 var a = libMirror('memory:a.dart');
71 var b = libMirror('memory:b.dart');
72
73 expect(map.exports[a], unorderedEquals([
74 new Export(a, b)
75 ]));
76
77 expect(map.transitiveExports(a), unorderedEquals([
78 new Export(a, b)
79 ]));
80
81 expect(map.exports[b], isEmpty);
82
83 expect(map.transitiveExports(b), isEmpty);
84 });
85 });
86
87 test('with one library with multiple exports', () {
88 return testExports({
89 'a.dart': 'export "b.dart";\nexport "c.dart";',
90 'b.dart': '', 'c.dart': ''
91 }).then((map) {
92 var a = libMirror('memory:a.dart');
93 var b = libMirror('memory:b.dart');
94 var c = libMirror('memory:c.dart');
95
96 expect(map.exports[a], unorderedEquals([
97 new Export(a, b),
98 new Export(a, c)
99 ]));
100
101 expect(map.transitiveExports(a), unorderedEquals([
102 new Export(a, b),
103 new Export(a, c)
104 ]));
105
106 expect(map.exports[b], isEmpty);
107 expect(map.transitiveExports(b), isEmpty);
108 expect(map.exports[c], isEmpty);
109 expect(map.transitiveExports(c), isEmpty);
110 });
111 });
112
113 test('with two libraries each with one export', () {
114 return testExports({
115 'a.dart': 'export "a_export.dart";',
116 'b.dart': 'export "b_export.dart";',
117 'a_export.dart': '',
118 'b_export.dart': ''
119 }).then((map) {
120 var a = libMirror('memory:a.dart');
121 var b = libMirror('memory:b.dart');
122 var a_export = libMirror('memory:a_export.dart');
123 var b_export = libMirror('memory:b_export.dart');
124
125 expect(map.exports[a], unorderedEquals([
126 new Export(a, a_export),
127 ]));
128 expect(map.transitiveExports(a), unorderedEquals([
129 new Export(a, a_export),
130 ]));
131
132 expect(map.transitiveExports(b), unorderedEquals([
133 new Export(b, b_export),
134 ]));
135 expect(map.exports[b], unorderedEquals([
136 new Export(b, b_export)
137 ]));
138
139 expect(map.exports[a_export], isEmpty);
140 expect(map.transitiveExports(a_export), isEmpty);
141 expect(map.exports[b_export], isEmpty);
142 expect(map.transitiveExports(b_export), isEmpty);
143 });
144 });
145
146 test('with a transitive export', () {
147 return testExports({
148 'a.dart': 'export "b.dart";',
149 'b.dart': 'export "c.dart";',
150 'c.dart': ''
151 }).then((map) {
152 var a = libMirror('memory:a.dart');
153 var b = libMirror('memory:b.dart');
154 var c = libMirror('memory:c.dart');
155
156 expect(map.exports[a], unorderedEquals([
157 new Export(a, b),
158 ]));
159 expect(map.transitiveExports(a), unorderedEquals([
160 new Export(a, b),
161 new Export(a, c),
162 ]));
163
164 expect(map.exports[b], unorderedEquals([
165 new Export(b, c),
166 ]));
167 expect(map.transitiveExports(b), unorderedEquals([
168 new Export(b, c),
169 ]));
170
171 expect(map.exports[c], isEmpty);
172 expect(map.transitiveExports(c), isEmpty);
173 });
174 });
175
176 test('with an export through an import', () {
177 return testExports({
178 'a.dart': 'import "b.dart";',
179 'b.dart': 'export "c.dart";',
180 'c.dart': ''
181 }).then((map) {
182 var a = libMirror('memory:a.dart');
183 var b = libMirror('memory:b.dart');
184 var c = libMirror('memory:c.dart');
185
186 expect(map.exports[b], unorderedEquals([
187 new Export(b, c),
188 ]));
189 expect(map.transitiveExports(b), unorderedEquals([
190 new Export(b, c),
191 ]));
192
193 expect(map.exports[a], isEmpty);
194 expect(map.exports[c], isEmpty);
195 expect(map.transitiveExports(a), isEmpty);
196 expect(map.transitiveExports(c), isEmpty);
197 });
198 });
199
200 test('with an export with a show combinator', () {
201 return testExports({
202 'a.dart': 'export "b.dart" show x, y;',
203 'b.dart': ''
204 }).then((map) {
205 var a = libMirror('memory:a.dart');
206 var b = libMirror('memory:b.dart');
207
208 expect(map.exports[a], unorderedEquals([
209 new Export(a, b, show: ['x', 'y'])
210 ]));
211 });
212 });
213
214 test('with an export with a hide combinator', () {
215 return testExports({
216 'a.dart': 'export "b.dart" hide x, y;',
217 'b.dart': ''
218 }).then((map) {
219 var a = libMirror('memory:a.dart');
220 var b = libMirror('memory:b.dart');
221
222 expect(map.exports[a], unorderedEquals([
223 new Export(a, b, hide: ['x', 'y'])
224 ]));
225 });
226 });
227
228 test('with an export with a show and a hide combinator', () {
229 return testExports({
230 'a.dart': 'export "b.dart" show x, y hide y, z;',
231 'b.dart': ''
232 }).then((map) {
233 var a = libMirror('memory:a.dart');
234 var b = libMirror('memory:b.dart');
235
236 expect(map.exports[a], unorderedEquals([
237 new Export(a, b, show: ['x'])
238 ]));
239 });
240 });
241
242 test('composes transitive exports', () {
243 return testExports({
244 'a.dart': 'export "b.dart" hide x;',
245 'b.dart': 'export "c.dart" hide y;',
246 'c.dart': ''
247 }).then((map) {
248 var a = libMirror('memory:a.dart');
249 var b = libMirror('memory:b.dart');
250 var c = libMirror('memory:c.dart');
251
252 expect(map.transitiveExports(a), unorderedEquals([
253 new Export(a, b, hide: ['x']),
254 new Export(a, c, hide: ['x', 'y'])
255 ]));
256 });
257 });
258
259 test('merges adjacent exports', () {
260 return testExports({
261 'a.dart': '''
262 export "b.dart" show x, y;
263 export "b.dart" hide y, z;
264 ''',
265 'b.dart': ''
266 }).then((map) {
267 var a = libMirror('memory:a.dart');
268 var b = libMirror('memory:b.dart');
269
270 expect(map.exports[a], unorderedEquals([
271 new Export(a, b, hide: ['z']),
272 ]));
273 expect(map.transitiveExports(a), unorderedEquals([
274 new Export(a, b, hide: ['z']),
275 ]));
276 });
277 });
278
279 test('merges adjacent exports transitively', () {
280 return testExports({
281 'a.dart': 'export "b.dart";\nexport "c.dart";',
282 'b.dart': 'export "d.dart" show x, y;',
283 'c.dart': 'export "d.dart" hide y, z;',
284 'd.dart': ''
285 }).then((map) {
286 var a = libMirror('memory:a.dart');
287 var b = libMirror('memory:b.dart');
288 var c = libMirror('memory:c.dart');
289 var d = libMirror('memory:d.dart');
290
291 expect(map.exports[a], unorderedEquals([
292 new Export(a, b),
293 new Export(a, c),
294 ]));
295 expect(map.transitiveExports(a), unorderedEquals([
296 new Export(a, b),
297 new Export(a, c),
298 new Export(a, d, hide: ['z']),
299 ]));
300 });
301 });
302
303 test('resolves package: exports', () {
304 return testExports({
305 'a.dart': 'export "package:b/b.dart";',
306 'packages/b/b.dart': ''
307 }).then((map) {
308 var a = libMirror('memory:a.dart');
309 var b = libMirror('package:b/b.dart');
310 expect(map.exports[a], unorderedEquals([
311 new Export(a, b)
312 ]));
313 });
314 });
315
316 test('ignores dart: exports', () {
317 return testExports({'a.dart': 'export "dart:async";'}).then((map) {
318 var a = libMirror('memory:a.dart');
319
320 expect(map.exports[a], isEmpty);
321 });
322 });
323
324 test('.parse() resolves package: imports', () {
325 return testExports({
326 'packages/a/a.dart': 'export "package:b/b.dart";',
327 'packages/b/b.dart': ''
328 }).then((map) {
329 var a = libMirror('package:a/a.dart');
330 var b = libMirror('package:b/b.dart');
331
332 expect(map.exports[a], unorderedEquals([
333 new Export(a, b)
334 ]));
335 });
336 });
337
338 test('.parse() ignores dart: imports', () {
339 return testExports({}).then((map) {
340 expect(map.exports, isEmpty);
341 });
342 });
343 });
344
345 group('Export', () {
346 test('normalizes hide and show', () {
347 expect(new Export(null, null, show: ['x', 'y'], hide: ['y', 'z']),
348 equals(new Export(null, null, show: ['x'])));
349 });
350
351 test("doesn't care about the order of show or hide", () {
352 expect(new Export(null, null, show: ['x', 'y']),
353 equals(new Export(null, null, show: ['y', 'x'])));
354 expect(new Export(null, null, hide: ['x', 'y']),
355 equals(new Export(null, null, hide: ['y', 'x'])));
356 });
357
358 test('with no combinators considers anything visible', () {
359 var export = new Export(null, null);
360 expect(export.isMemberVisible('x'), isTrue);
361 expect(export.isMemberVisible('y'), isTrue);
362 expect(export.isMemberVisible('z'), isTrue);
363 });
364
365 test('with hide combinators considers anything not hidden visible', () {
366 var export = new Export(null, null, hide: ['x', 'y']);
367 expect(export.isMemberVisible('x'), isFalse);
368 expect(export.isMemberVisible('y'), isFalse);
369 expect(export.isMemberVisible('z'), isTrue);
370 });
371
372 test('with show combinators considers anything not shown invisible', () {
373 var export = new Export(null, null, show: ['x', 'y']);
374 expect(export.isMemberVisible('x'), isTrue);
375 expect(export.isMemberVisible('y'), isTrue);
376 expect(export.isMemberVisible('z'), isFalse);
377 });
378
379 test('composing uses the parent exporter and child path', () {
380 return testExports({
381 'exporter1.dart': '',
382 'exporter2.dart': '',
383 'path1.dart': '',
384 'path2.dart': ''
385 }).then((map) {
386 var exporter1 = libMirror('memory:exporter1.dart');
387 var exporter2 = libMirror('memory:exporter2.dart');
388 var path1 = libMirror('memory:path1.dart');
389 var path2 = libMirror('memory:path2.dart');
390 expect(new Export(exporter1, path1)
391 .compose(new Export(exporter2, path2)),
392 equals(new Export(exporter1, path2)));
393 });
394 });
395
396 test('composing show . show takes the intersection', () {
397 expect(new Export(null, null, show: ['x', 'y'])
398 .compose(new Export(null, null, show: ['y', 'z'])),
399 equals(new Export(null, null, show: ['y'])));
400 });
401
402 test('composing show . hide takes the difference', () {
403 expect(new Export(null, null, show: ['x', 'y'])
404 .compose(new Export(null, null, hide: ['y', 'z'])),
405 equals(new Export(null, null, show: ['x'])));
406 });
407
408 test('composing hide . show takes the reverse difference', () {
409 expect(new Export(null, null, hide: ['x', 'y'])
410 .compose(new Export(null, null, show: ['y', 'z'])),
411 equals(new Export(null, null, show: ['z'])));
412 });
413
414 test('composing hide . hide takes the union', () {
415 expect(new Export(null, null, hide: ['x', 'y'])
416 .compose(new Export(null, null, hide: ['y', 'z'])),
417 equals(new Export(null, null, hide: ['x', 'y', 'z'])));
418 });
419
420 test('merging requires identical exporters and paths', () {
421 return testExports({
422 'exporter1.dart': '',
423 'exporter2.dart': '',
424 'path1.dart': '',
425 'path2.dart': ''
426 }).then((map) {
427 var exporter1 = libMirror('memory:exporter1.dart');
428 var exporter2 = libMirror('memory:exporter2.dart');
429 var path1 = libMirror('memory:path1.dart');
430 var path2 = libMirror('memory:path2.dart');
431 expect(() => new Export(exporter1, null)
432 .merge(new Export(exporter2, null)),
433 throwsA(isArgumentError));
434 expect(() => new Export(null, path1)
435 .merge(new Export(null, path2)),
436 throwsA(isArgumentError));
437 expect(new Export(null, null)
438 .merge(new Export(null, null)),
439 equals(new Export(null, null)));
440 });
441 });
442
443 test('merging show + show takes the union', () {
444 expect(new Export(null, null, show: ['x', 'y'])
445 .merge(new Export(null, null, show: ['y', 'z'])),
446 equals(new Export(null, null, show: ['x', 'y', 'z'])));
447 });
448
449 test('merging show + hide takes the difference', () {
450 expect(new Export(null, null, show: ['x', 'y'])
451 .merge(new Export(null, null, hide: ['y', 'z'])),
452 equals(new Export(null, null, hide: ['z'])));
453 });
454
455 test('merging hide + show takes the difference', () {
456 expect(new Export(null, null, hide: ['x', 'y'])
457 .merge(new Export(null, null, show: ['y', 'z'])),
458 equals(new Export(null, null, hide: ['x'])));
459 });
460
461 test('merging hide + hide takes the intersection', () {
462 expect(new Export(null, null, hide: ['x', 'y'])
463 .merge(new Export(null, null, hide: ['y', 'z'])),
464 equals(new Export(null, null, hide: ['y'])));
465 });
466 });
467 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/dartdoc/test/dartdoc_test.dart ('k') | sdk/lib/_internal/dartdoc/test/markdown_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698