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

Side by Side Diff: pkg/analyzer/test/generated/bazel_test.dart

Issue 2403733002: Implement BazelPackageUriResolver.restoreAbsolute(). (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/bazel.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library analyzer.test.generated.bazel_test; 5 library analyzer.test.generated.bazel_test;
6 6
7 import 'package:analyzer/file_system/memory_file_system.dart'; 7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/generated/bazel.dart'; 8 import 'package:analyzer/src/generated/bazel.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; 11 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 import 'package:typed_mock/typed_mock.dart';
12 13
13 main() { 14 main() {
14 defineReflectiveSuite(() { 15 defineReflectiveSuite(() {
15 defineReflectiveTests(BazelFileUriResolverTest); 16 defineReflectiveTests(BazelFileUriResolverTest);
16 defineReflectiveTests(BazelPackageUriResolverTest); 17 defineReflectiveTests(BazelPackageUriResolverTest);
17 defineReflectiveTests(BazelWorkspaceTest); 18 defineReflectiveTests(BazelWorkspaceTest);
18 }); 19 });
19 } 20 }
20 21
21 @reflectiveTest 22 @reflectiveTest
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 _addResources([ 384 _addResources([
384 '/workspace/WORKSPACE', 385 '/workspace/WORKSPACE',
385 '/workspace/bazel-genfiles/', 386 '/workspace/bazel-genfiles/',
386 '/workspace/my/foo/lib/foo1.dart', 387 '/workspace/my/foo/lib/foo1.dart',
387 ]); 388 ]);
388 _assertResolve( 389 _assertResolve(
389 'package:my.foo/foo1.dart', '/workspace/my/foo/lib/foo1.dart', 390 'package:my.foo/foo1.dart', '/workspace/my/foo/lib/foo1.dart',
390 exists: true); 391 exists: true);
391 } 392 }
392 393
394 void test_restoreAbsolute_noPackageName_workspace() {
395 _addResources([
396 '/workspace/WORKSPACE',
397 '/workspace/bazel-genfiles/',
398 '/workspace/lib/foo1.dart',
399 '/workspace/foo/lib/foo2.dart',
400 ]);
401 _assertRestore('/workspace/lib/foo1.dart', null);
402 _assertRestore('/workspace/foo/lib/foo2.dart', null);
403 }
404
405 void test_restoreAbsolute_noPathInLib_bin() {
406 _addResources([
407 '/workspace/WORKSPACE',
408 '/workspace/bazel-genfiles/',
409 '/workspace/bazel-bin/my/foo/lib/foo1.dart',
410 ]);
411 _assertRestore('/workspace/bazel-bin', null);
412 _assertRestore('/workspace/bazel-bin/my', null);
413 _assertRestore('/workspace/bazel-bin/my/foo', null);
414 _assertRestore('/workspace/bazel-bin/my/foo/lib', null);
415 }
416
417 void test_restoreAbsolute_noPathInLib_genfiles() {
418 _addResources([
419 '/workspace/WORKSPACE',
420 '/workspace/bazel-genfiles/',
421 '/workspace/bazel-genfiles/my/foo/lib/foo1.dart',
422 ]);
423 _assertRestore('/workspace/bazel-genfiles', null);
424 _assertRestore('/workspace/bazel-genfiles/my', null);
425 _assertRestore('/workspace/bazel-genfiles/my/foo', null);
426 _assertRestore('/workspace/bazel-genfiles/my/foo/lib', null);
427 }
428
429 void test_restoreAbsolute_noPathInLib_workspace() {
430 _addResources([
431 '/workspace/WORKSPACE',
432 '/workspace/bazel-genfiles/',
433 '/workspace/my/foo/lib/foo1.dart',
434 ]);
435 _assertRestore('/workspace', null);
436 _assertRestore('/workspace/my', null);
437 _assertRestore('/workspace/my/foo', null);
438 _assertRestore('/workspace/my/foo/lib', null);
439 }
440
393 void _addResources(List<String> paths, {String workspacePath: '/workspace'}) { 441 void _addResources(List<String> paths, {String workspacePath: '/workspace'}) {
394 for (String path in paths) { 442 for (String path in paths) {
395 if (path.endsWith('/')) { 443 if (path.endsWith('/')) {
396 provider.newFolder(_p(path.substring(0, path.length - 1))); 444 provider.newFolder(_p(path.substring(0, path.length - 1)));
397 } else { 445 } else {
398 provider.newFile(_p(path), ''); 446 provider.newFile(_p(path), '');
399 } 447 }
400 } 448 }
401 workspace = BazelWorkspace.find(provider, _p(workspacePath)); 449 workspace = BazelWorkspace.find(provider, _p(workspacePath));
402 resolver = new BazelPackageUriResolver(workspace); 450 resolver = new BazelPackageUriResolver(workspace);
403 } 451 }
404 452
405 void _assertResolve(String uriStr, String posixPath, {bool exists: true}) { 453 void _assertResolve(String uriStr, String posixPath,
454 {bool exists: true, bool restore: true}) {
406 Uri uri = Uri.parse(uriStr); 455 Uri uri = Uri.parse(uriStr);
407 Source source = resolver.resolveAbsolute(uri); 456 Source source = resolver.resolveAbsolute(uri);
408 expect(source, isNotNull); 457 expect(source, isNotNull);
409 expect(source.fullName, _p(posixPath)); 458 expect(source.fullName, _p(posixPath));
410 expect(source.uri, uri); 459 expect(source.uri, uri);
411 expect(source.exists(), exists); 460 expect(source.exists(), exists);
461 // If enabled, test also "restoreAbsolute".
462 if (restore) {
463 Uri uri = resolver.restoreAbsolute(source);
464 expect(uri.toString(), uriStr);
465 }
466 }
467
468 void _assertRestore(String posixPath, String expectedUri) {
469 String path = _p(posixPath);
470 _MockSource source = new _MockSource(path);
471 Uri uri = resolver.restoreAbsolute(source);
472 expect(uri?.toString(), expectedUri);
412 } 473 }
413 } 474 }
414 475
415 @reflectiveTest 476 @reflectiveTest
416 class BazelWorkspaceTest extends _BaseTest { 477 class BazelWorkspaceTest extends _BaseTest {
417 void test_find_fail_notAbsolute() { 478 void test_find_fail_notAbsolute() {
418 expect(() => BazelWorkspace.find(provider, _p('not_absolute')), 479 expect(() => BazelWorkspace.find(provider, _p('not_absolute')),
419 throwsArgumentError); 480 throwsArgumentError);
420 } 481 }
421 482
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 631 }
571 632
572 class _BaseTest { 633 class _BaseTest {
573 final MemoryResourceProvider provider = new MemoryResourceProvider(); 634 final MemoryResourceProvider provider = new MemoryResourceProvider();
574 635
575 /** 636 /**
576 * Return the [provider] specific path for the given Posix [path]. 637 * Return the [provider] specific path for the given Posix [path].
577 */ 638 */
578 String _p(String path) => provider.convertPath(path); 639 String _p(String path) => provider.convertPath(path);
579 } 640 }
641
642 class _MockSource extends TypedMock implements Source {
643 final String fullName;
644 _MockSource(this.fullName);
645 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/bazel.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698