OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 'dart:io'; | 5 import 'dart:io'; |
6 import 'dart:uri'; | |
6 | 7 |
7 import 'package:pathos/path.dart' as pathos; | 8 import 'package:pathos/path.dart' as pathos; |
8 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
9 | 10 |
10 import '../lib/src/export_map.dart'; | 11 import '../lib/src/export_map.dart'; |
12 import '../lib/src/dartdoc/utils.dart'; | |
11 | 13 |
12 String tempDir; | 14 String tempDir; |
13 | 15 |
14 main() { | 16 main() { |
15 group('ExportMap', () { | 17 group('ExportMap', () { |
16 setUp(createTempDir); | 18 setUp(createTempDir); |
17 tearDown(deleteTempDir); | 19 tearDown(deleteTempDir); |
18 | 20 |
19 test('with an empty library', () { | 21 test('with an empty library', () { |
20 createLibrary('lib.dart'); | 22 createLibrary('lib.dart'); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 test('resolves package: exports', () { | 235 test('resolves package: exports', () { |
234 createLibrary('a.dart', 'export "package:b/b.dart";'); | 236 createLibrary('a.dart', 'export "package:b/b.dart";'); |
235 var bPath = pathos.join('packages', 'b', 'b.dart'); | 237 var bPath = pathos.join('packages', 'b', 'b.dart'); |
236 createLibrary(bPath); | 238 createLibrary(bPath); |
237 var map = parse(['a.dart']); | 239 var map = parse(['a.dart']); |
238 | 240 |
239 expect(map.exports[libPath('a.dart')], unorderedEquals([ | 241 expect(map.exports[libPath('a.dart')], unorderedEquals([ |
240 new Export(libPath('a.dart'), libPath(bPath)) | 242 new Export(libPath('a.dart'), libPath(bPath)) |
241 ])); | 243 ])); |
242 }); | 244 }); |
245 | |
246 test('ignores dart: exports', () { | |
247 createLibrary('a.dart', 'export "dart:async";'); | |
248 var map = parse(['a.dart']); | |
249 expect(map.exports[libPath('a.dart')], isEmpty); | |
250 }); | |
251 | |
252 test('.parse() resolves package: imports', () { | |
253 var aPath = pathos.join('packages', 'a', 'a.dart'); | |
254 createLibrary(aPath, 'export "package:b/b.dart";'); | |
255 var bPath = pathos.join('packages', 'b', 'b.dart'); | |
256 createLibrary(bPath); | |
257 var map = new ExportMap.parse( | |
258 [Uri.parse('package:a/a.dart')], | |
259 pathos.join(tempDir, 'packages')); | |
260 | |
261 expect(map.exports[libPath(aPath)], unorderedEquals([ | |
262 new Export(libPath(aPath), libPath(bPath)) | |
263 ])); | |
264 }); | |
265 | |
266 test('.parse() ignores dart: imports', () { | |
267 var map = new ExportMap.parse( | |
268 [Uri.parse('dart:async')], | |
269 pathos.join(tempDir, 'packages')); | |
270 expect(map.exports, isEmpty); | |
271 }); | |
243 }); | 272 }); |
244 | 273 |
245 group('Export', () { | 274 group('Export', () { |
246 test('normalizes hide and show', () { | 275 test('normalizes hide and show', () { |
247 expect(new Export('', '', show: ['x', 'y'], hide: ['y', 'z']), | 276 expect(new Export('', '', show: ['x', 'y'], hide: ['y', 'z']), |
248 equals(new Export('', '', show: ['x']))); | 277 equals(new Export('', '', show: ['x']))); |
249 }); | 278 }); |
250 | 279 |
251 test("doesn't care about the order of show or hide", () { | 280 test("doesn't care about the order of show or hide", () { |
252 expect(new Export('', '', show: ['x', 'y']), | 281 expect(new Export('', '', show: ['x', 'y']), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 | 366 |
338 test('merging hide + hide takes the intersection', () { | 367 test('merging hide + hide takes the intersection', () { |
339 expect(new Export('', '', hide: ['x', 'y']) | 368 expect(new Export('', '', hide: ['x', 'y']) |
340 .merge(new Export('', '', hide: ['y', 'z'])), | 369 .merge(new Export('', '', hide: ['y', 'z'])), |
341 equals(new Export('', '', hide: ['y']))); | 370 equals(new Export('', '', hide: ['y']))); |
342 }); | 371 }); |
343 }); | 372 }); |
344 } | 373 } |
345 | 374 |
346 ExportMap parse(List<String> libraries) => | 375 ExportMap parse(List<String> libraries) => |
347 new ExportMap.parse(libraries.map(libPath), pathos.join(tempDir, 'packages')); | 376 new ExportMap.parse( |
377 libraries.map(libPath).map(pathToFileUri), | |
Andrei Mouravski
2013/04/09 01:48:36
I would put the second map on the next line to be
nweiz
2013/04/09 02:10:23
Done.
| |
378 pathos.join(tempDir, 'packages')); | |
348 | 379 |
349 void createLibrary(String name, [String contents]) { | 380 void createLibrary(String name, [String contents]) { |
350 if (contents == null) contents = ''; | 381 if (contents == null) contents = ''; |
351 new Directory(pathos.dirname(libPath(name))).createSync(recursive: true); | 382 new Directory(pathos.dirname(libPath(name))).createSync(recursive: true); |
352 new File(libPath(name)).writeAsStringSync(''' | 383 new File(libPath(name)).writeAsStringSync(''' |
353 library ${pathos.basename(name)}; | 384 library ${pathos.basename(name)}; |
354 $contents | 385 $contents |
355 '''); | 386 '''); |
356 } | 387 } |
357 | 388 |
358 String libPath(String name) => pathos.normalize(pathos.join(tempDir, name)); | 389 String libPath(String name) => pathos.normalize(pathos.join(tempDir, name)); |
359 | 390 |
360 void createTempDir() { | 391 void createTempDir() { |
361 tempDir = new Directory('').createTempSync().path; | 392 tempDir = new Directory('').createTempSync().path; |
362 new Directory(pathos.join(tempDir, 'packages')).createSync(); | 393 new Directory(pathos.join(tempDir, 'packages')).createSync(); |
363 } | 394 } |
364 | 395 |
365 void deleteTempDir() { | 396 void deleteTempDir() { |
366 new Directory(tempDir).deleteSync(recursive: true); | 397 new Directory(tempDir).deleteSync(recursive: true); |
367 } | 398 } |
OLD | NEW |