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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/bazel.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/bazel_test.dart
diff --git a/pkg/analyzer/test/generated/bazel_test.dart b/pkg/analyzer/test/generated/bazel_test.dart
index af24c22ce71ab9a00df93af5ea06b4f306f885df..cc1a75a405222ccb116d97a5816840477a6bfc87 100644
--- a/pkg/analyzer/test/generated/bazel_test.dart
+++ b/pkg/analyzer/test/generated/bazel_test.dart
@@ -9,6 +9,7 @@ import 'package:analyzer/src/generated/bazel.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'package:typed_mock/typed_mock.dart';
main() {
defineReflectiveSuite(() {
@@ -390,6 +391,53 @@ class BazelPackageUriResolverTest extends _BaseTest {
exists: true);
}
+ void test_restoreAbsolute_noPackageName_workspace() {
+ _addResources([
+ '/workspace/WORKSPACE',
+ '/workspace/bazel-genfiles/',
+ '/workspace/lib/foo1.dart',
+ '/workspace/foo/lib/foo2.dart',
+ ]);
+ _assertRestore('/workspace/lib/foo1.dart', null);
+ _assertRestore('/workspace/foo/lib/foo2.dart', null);
+ }
+
+ void test_restoreAbsolute_noPathInLib_bin() {
+ _addResources([
+ '/workspace/WORKSPACE',
+ '/workspace/bazel-genfiles/',
+ '/workspace/bazel-bin/my/foo/lib/foo1.dart',
+ ]);
+ _assertRestore('/workspace/bazel-bin', null);
+ _assertRestore('/workspace/bazel-bin/my', null);
+ _assertRestore('/workspace/bazel-bin/my/foo', null);
+ _assertRestore('/workspace/bazel-bin/my/foo/lib', null);
+ }
+
+ void test_restoreAbsolute_noPathInLib_genfiles() {
+ _addResources([
+ '/workspace/WORKSPACE',
+ '/workspace/bazel-genfiles/',
+ '/workspace/bazel-genfiles/my/foo/lib/foo1.dart',
+ ]);
+ _assertRestore('/workspace/bazel-genfiles', null);
+ _assertRestore('/workspace/bazel-genfiles/my', null);
+ _assertRestore('/workspace/bazel-genfiles/my/foo', null);
+ _assertRestore('/workspace/bazel-genfiles/my/foo/lib', null);
+ }
+
+ void test_restoreAbsolute_noPathInLib_workspace() {
+ _addResources([
+ '/workspace/WORKSPACE',
+ '/workspace/bazel-genfiles/',
+ '/workspace/my/foo/lib/foo1.dart',
+ ]);
+ _assertRestore('/workspace', null);
+ _assertRestore('/workspace/my', null);
+ _assertRestore('/workspace/my/foo', null);
+ _assertRestore('/workspace/my/foo/lib', null);
+ }
+
void _addResources(List<String> paths, {String workspacePath: '/workspace'}) {
for (String path in paths) {
if (path.endsWith('/')) {
@@ -402,13 +450,26 @@ class BazelPackageUriResolverTest extends _BaseTest {
resolver = new BazelPackageUriResolver(workspace);
}
- void _assertResolve(String uriStr, String posixPath, {bool exists: true}) {
+ void _assertResolve(String uriStr, String posixPath,
+ {bool exists: true, bool restore: true}) {
Uri uri = Uri.parse(uriStr);
Source source = resolver.resolveAbsolute(uri);
expect(source, isNotNull);
expect(source.fullName, _p(posixPath));
expect(source.uri, uri);
expect(source.exists(), exists);
+ // If enabled, test also "restoreAbsolute".
+ if (restore) {
+ Uri uri = resolver.restoreAbsolute(source);
+ expect(uri.toString(), uriStr);
+ }
+ }
+
+ void _assertRestore(String posixPath, String expectedUri) {
+ String path = _p(posixPath);
+ _MockSource source = new _MockSource(path);
+ Uri uri = resolver.restoreAbsolute(source);
+ expect(uri?.toString(), expectedUri);
}
}
@@ -577,3 +638,8 @@ class _BaseTest {
*/
String _p(String path) => provider.convertPath(path);
}
+
+class _MockSource extends TypedMock implements Source {
+ final String fullName;
+ _MockSource(this.fullName);
+}
« 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