| 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(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/', 'A/B/', ''].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(), |
| 44 ['/r1/', '/r2/', '/A/B/', '/']); |
| 45 }); |
| 46 |
| 47 test('file URIs are not converted', () async { |
| 48 write('r1', 'a/b/1.dart'); |
| 49 write('', 'a/b/1.dart'); |
| 50 expect(await effectiveUriOf('file:///a/b/1.dart'), 'file:///a/b/1.dart'); |
| 51 }); |
| 52 |
| 53 test('only URIs with the marker scheme are converted', () async { |
| 54 write('r1', 'a/b/2.dart'); |
| 55 expect(await effectiveUriOf('multi-root:///a/b/2.dart'), |
| 56 'file:///r1/a/b/2.dart'); |
| 57 expect(await effectiveUriOf('foo-root:///a/b/2.dart'), |
| 58 'foo-root:///a/b/2.dart'); |
| 59 }); |
| 60 |
| 61 test('roots are visited in declaration order (match first root)', () async { |
| 62 write('r1', 'a/3.dart'); |
| 63 write('r2', 'a/3.dart'); |
| 64 write('', 'a/3.dart'); |
| 65 expect( |
| 66 await effectiveUriOf('multi-root:///a/3.dart'), 'file:///r1/a/3.dart'); |
| 67 }); |
| 68 |
| 69 test('roots are visited in declaration order (match second root)', () async { |
| 70 write('r2', 'a/4.dart'); |
| 71 write('', 'a/4.dart'); |
| 72 expect( |
| 73 await effectiveUriOf('multi-root:///a/4.dart'), 'file:///r2/a/4.dart'); |
| 74 }); |
| 75 |
| 76 test('roots are visited in declaration order (match last root)', () async { |
| 77 write('', 'a/5.dart'); |
| 78 expect(await effectiveUriOf('multi-root:///a/5.dart'), 'file:///a/5.dart'); |
| 79 }); |
| 80 |
| 81 test('operations are forwarded to the correct target', () async { |
| 82 write('r1', 'a/6.dart'); |
| 83 write('r2', 'a/6.dart'); |
| 84 write('r2', 'a/7.dart'); |
| 85 |
| 86 expect(await exists('multi-root:///a/6.dart'), isTrue); |
| 87 expect(await read('multi-root:///a/6.dart'), 'file:///r1/a/6.dart'); |
| 88 |
| 89 expect(await exists('multi-root:///a/7.dart'), isTrue); |
| 90 expect(await read('multi-root:///a/7.dart'), 'file:///r2/a/7.dart'); |
| 91 expect(await exists('file:///r2/a/7.dart'), isTrue); |
| 92 expect(await read('file:///r2/a/7.dart'), 'file:///r2/a/7.dart'); |
| 93 |
| 94 expect(await exists('multi-root:///a/8.dart'), isFalse); |
| 95 }); |
| 96 |
| 97 test('multi-root expects absolute paths', () async { |
| 98 write('A/B', 'a/8.dart'); |
| 99 |
| 100 expect( |
| 101 await effectiveUriOf('multi-root:///a/8.dart'), 'file:///A/B/a/8.dart'); |
| 102 expect(await effectiveUriOf('multi-root:///../B/a/8.dart'), |
| 103 'multi-root:///B/a/8.dart'); |
| 104 |
| 105 // Embedding the full absolute path after a few `..` gets resolved because |
| 106 // we have also included '' as a root. |
| 107 expect(await effectiveUriOf('multi-root:///../A/B/a/8.dart'), |
| 108 'file:///A/B/a/8.dart'); |
| 109 expect(await effectiveUriOf('multi-root:///../../A/B/a/8.dart'), |
| 110 'file:///A/B/a/8.dart'); |
| 111 |
| 112 // If we remove '' as a root, those URIs are not resolved. |
| 113 multiRoot = |
| 114 new MultiRootFileSystem('multi-root', [root.resolve('A/B/')], memoryFs); |
| 115 expect(await effectiveUriOf('multi-root:///../A/B/a/8.dart'), |
| 116 'multi-root:///A/B/a/8.dart'); |
| 117 expect(await effectiveUriOf('multi-root:///../../A/B/a/8.dart'), |
| 118 'multi-root:///A/B/a/8.dart'); |
| 119 }); |
| 120 } |
| OLD | NEW |