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

Unified Diff: pkg/front_end/test/src/multi_root_file_system_test.dart

Issue 2964323002: Add support for multi-roots (Closed)
Patch Set: extra test Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/multi_root_file_system.dart ('k') | pkg/front_end/test/summary_generator_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/test/src/multi_root_file_system_test.dart
diff --git a/pkg/front_end/test/src/multi_root_file_system_test.dart b/pkg/front_end/test/src/multi_root_file_system_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..85e4d397eca7a6986dd8a242cc4ed7e84f4eb833
--- /dev/null
+++ b/pkg/front_end/test/src/multi_root_file_system_test.dart
@@ -0,0 +1,120 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library front_end.test.src.multi_root_file_system.dart;
+
+import 'dart:async';
+
+import 'package:front_end/memory_file_system.dart';
+import 'package:front_end/src/multi_root_file_system.dart';
+
+import 'package:test/test.dart';
+
+var root = Uri.parse('file:///');
+
+main() {
+ var memoryFs;
+ var rootUris;
+ var multiRoot;
+
+ write(String multiRoot, String path) {
+ var realPath = multiRoot == '' ? path : '$multiRoot/$path';
+ var uri = root.resolve(realPath);
+ memoryFs.entityForUri(uri).writeAsStringSync('$uri');
+ }
+
+ Future<String> read(String uri) =>
+ multiRoot.entityForUri(Uri.parse(uri)).readAsString();
+
+ Future<bool> exists(String uri) =>
+ multiRoot.entityForUri(Uri.parse(uri)).exists();
+
+ Future<String> effectiveUriOf(String uri) async =>
+ (await multiRoot.entityForUri(Uri.parse(uri)).delegate).uri.toString();
+
+ setUp(() {
+ memoryFs = new MemoryFileSystem(root);
+ rootUris = ['r1', 'r2/', 'A/B/', ''].map((r) => root.resolve(r)).toList();
+ multiRoot = new MultiRootFileSystem('multi-root', rootUris, memoryFs);
+ });
+
+ test('roots are normalized', () async {
+ expect(multiRoot.roots.map((x) => x.path).toList(),
+ ['/r1/', '/r2/', '/A/B/', '/']);
+ });
+
+ test('file URIs are not converted', () async {
+ write('r1', 'a/b/1.dart');
+ write('', 'a/b/1.dart');
+ expect(await effectiveUriOf('file:///a/b/1.dart'), 'file:///a/b/1.dart');
+ });
+
+ test('only URIs with the marker scheme are converted', () async {
+ write('r1', 'a/b/2.dart');
+ expect(await effectiveUriOf('multi-root:///a/b/2.dart'),
+ 'file:///r1/a/b/2.dart');
+ expect(await effectiveUriOf('foo-root:///a/b/2.dart'),
+ 'foo-root:///a/b/2.dart');
+ });
+
+ test('roots are visited in declaration order (match first root)', () async {
+ write('r1', 'a/3.dart');
+ write('r2', 'a/3.dart');
+ write('', 'a/3.dart');
+ expect(
+ await effectiveUriOf('multi-root:///a/3.dart'), 'file:///r1/a/3.dart');
+ });
+
+ test('roots are visited in declaration order (match second root)', () async {
+ write('r2', 'a/4.dart');
+ write('', 'a/4.dart');
+ expect(
+ await effectiveUriOf('multi-root:///a/4.dart'), 'file:///r2/a/4.dart');
+ });
+
+ test('roots are visited in declaration order (match last root)', () async {
+ write('', 'a/5.dart');
+ expect(await effectiveUriOf('multi-root:///a/5.dart'), 'file:///a/5.dart');
+ });
+
+ test('operations are forwarded to the correct target', () async {
+ write('r1', 'a/6.dart');
+ write('r2', 'a/6.dart');
+ write('r2', 'a/7.dart');
+
+ expect(await exists('multi-root:///a/6.dart'), isTrue);
+ expect(await read('multi-root:///a/6.dart'), 'file:///r1/a/6.dart');
+
+ expect(await exists('multi-root:///a/7.dart'), isTrue);
+ expect(await read('multi-root:///a/7.dart'), 'file:///r2/a/7.dart');
+ expect(await exists('file:///r2/a/7.dart'), isTrue);
+ expect(await read('file:///r2/a/7.dart'), 'file:///r2/a/7.dart');
+
+ expect(await exists('multi-root:///a/8.dart'), isFalse);
+ });
+
+ test('multi-root expects absolute paths', () async {
+ write('A/B', 'a/8.dart');
+
+ expect(
+ await effectiveUriOf('multi-root:///a/8.dart'), 'file:///A/B/a/8.dart');
+ expect(await effectiveUriOf('multi-root:///../B/a/8.dart'),
+ 'multi-root:///B/a/8.dart');
+
+ // Embedding the full absolute path after a few `..` gets resolved because
+ // we have also included '' as a root.
+ expect(await effectiveUriOf('multi-root:///../A/B/a/8.dart'),
+ 'file:///A/B/a/8.dart');
+ expect(await effectiveUriOf('multi-root:///../../A/B/a/8.dart'),
+ 'file:///A/B/a/8.dart');
+
+ // If we remove '' as a root, those URIs are not resolved.
+ multiRoot =
+ new MultiRootFileSystem('multi-root', [root.resolve('A/B/')], memoryFs);
+ expect(await effectiveUriOf('multi-root:///../A/B/a/8.dart'),
+ 'multi-root:///A/B/a/8.dart');
+ expect(await effectiveUriOf('multi-root:///../../A/B/a/8.dart'),
+ 'multi-root:///A/B/a/8.dart');
+ });
+}
« no previous file with comments | « pkg/front_end/lib/src/multi_root_file_system.dart ('k') | pkg/front_end/test/summary_generator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698