Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 library front_end.test.src.multi_root_file_system.dart; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:front_end/memory_file_system.dart'; | |
| 10 import 'package:front_end/src/multi_root_file_system.dart'; | |
| 11 | |
| 12 import 'package:test/test.dart'; | |
| 13 | |
| 14 var root = Uri.parse('file:///'); | |
| 15 | |
| 16 main() { | |
| 17 var memoryFs; | |
| 18 var rootUris; | |
| 19 var multiRoot; | |
| 20 | |
| 21 write(String multiRoot, String path) { | |
| 22 var realPath = multiRoot == '' ? path : '$multiRoot/$path'; | |
| 23 var uri = root.resolve(multiRoot).resolve(realPath); | |
| 24 memoryFs.entityForUri(uri).writeAsStringSync('$uri'); | |
| 25 } | |
| 26 | |
| 27 Future<String> read(String uri) => | |
| 28 multiRoot.entityForUri(Uri.parse(uri)).readAsString(); | |
| 29 | |
| 30 Future<bool> exists(String uri) => | |
| 31 multiRoot.entityForUri(Uri.parse(uri)).exists(); | |
| 32 | |
| 33 Future<String> effectiveUriOf(String uri) async => | |
| 34 (await multiRoot.entityForUri(Uri.parse(uri)).delegate).uri.toString(); | |
| 35 | |
| 36 setUp(() { | |
| 37 memoryFs = new MemoryFileSystem(root); | |
| 38 rootUris = ['r1', 'r2/', ''].map((r) => root.resolve(r)).toList(); | |
| 39 multiRoot = new MultiRootFileSystem('multi-root', rootUris, memoryFs); | |
| 40 }); | |
| 41 | |
| 42 test('roots are normalized', () async { | |
| 43 expect(multiRoot.roots.map((x) => x.path).toList(), ['/r1/', '/r2/', '/']); | |
| 44 }); | |
| 45 | |
| 46 test('file URIs are not converted', () async { | |
| 47 write('r1', 'a/b/1.dart'); | |
| 48 write('', 'a/b/1.dart'); | |
| 49 expect(await effectiveUriOf('file:///a/b/1.dart'), 'file:///a/b/1.dart'); | |
| 50 }); | |
| 51 | |
| 52 test('only URIs with the marker scheme are converted', () async { | |
| 53 write('r1', 'a/b/2.dart'); | |
| 54 expect(await effectiveUriOf('multi-root:///a/b/2.dart'), | |
| 55 'file:///r1/a/b/2.dart'); | |
| 56 expect(await effectiveUriOf('foo-root:///a/b/2.dart'), | |
| 57 'foo-root:///a/b/2.dart'); | |
| 58 }); | |
| 59 | |
| 60 test('roots are visited in declaration order (match first root)', () async { | |
| 61 write('r1', 'a/3.dart'); | |
| 62 write('r2', 'a/3.dart'); | |
| 63 write('', 'a/3.dart'); | |
| 64 expect( | |
| 65 await effectiveUriOf('multi-root:///a/3.dart'), 'file:///r1/a/3.dart'); | |
| 66 }); | |
| 67 | |
| 68 test('roots are visited in declaration order (match second root)', () async { | |
| 69 write('r2', 'a/4.dart'); | |
| 70 write('', 'a/4.dart'); | |
| 71 expect( | |
| 72 await effectiveUriOf('multi-root:///a/4.dart'), 'file:///r2/a/4.dart'); | |
| 73 }); | |
| 74 | |
| 75 test('roots are visited in declaration order (match last root)', () async { | |
| 76 write('', 'a/5.dart'); | |
| 77 expect(await effectiveUriOf('multi-root:///a/5.dart'), 'file:///a/5.dart'); | |
| 78 }); | |
| 79 | |
| 80 test('operations are forwarded to the correct target', () async { | |
| 81 write('r1', 'a/6.dart'); | |
| 82 write('r2', 'a/6.dart'); | |
| 83 write('r2', 'a/7.dart'); | |
| 84 | |
| 85 expect(await exists('multi-root:///a/6.dart'), isTrue); | |
| 86 expect(await read('multi-root:///a/6.dart'), 'file:///r1/a/6.dart'); | |
| 87 | |
| 88 expect(await exists('multi-root:///a/7.dart'), isTrue); | |
| 89 expect(await read('multi-root:///a/7.dart'), 'file:///r2/a/7.dart'); | |
| 90 expect(await exists('file:///r2/a/7.dart'), isTrue); | |
| 91 expect(await read('file:///r2/a/7.dart'), 'file:///r2/a/7.dart'); | |
| 92 | |
| 93 expect(await exists('multi-root:///a/8.dart'), isFalse); | |
| 94 }); | |
| 95 } | |
|
Paul Berry
2017/07/04 15:32:17
Can we add some tests to check that "multi-root://
Siggi Cherem (dart-lang)
2017/07/05 22:48:30
Done.
| |
| OLD | NEW |