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

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

Issue 2964323002: Add support for multi-roots (Closed)
Patch Set: Created 3 years, 6 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
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..f66ce6db109a3058780e3240d1607179572ef95a
--- /dev/null
+++ b/pkg/front_end/test/src/multi_root_file_system_test.dart
@@ -0,0 +1,95 @@
+// 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(multiRoot).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/', ''].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/', '/']);
+ });
+
+ 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);
+ });
+}
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.

Powered by Google App Engine
This is Rietveld 408576698