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

Unified Diff: pkg/front_end/test/src/base/libraries_spec_test.dart

Issue 2986303003: Switch FE to use the libraries.json format. (Closed)
Patch Set: Created 3 years, 4 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/base/libraries_spec_test.dart
diff --git a/pkg/front_end/test/src/base/libraries_spec_test.dart b/pkg/front_end/test/src/base/libraries_spec_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b97724a04fc9c665fad026c1f43bf57ae81d640e
--- /dev/null
+++ b/pkg/front_end/test/src/base/libraries_spec_test.dart
@@ -0,0 +1,206 @@
+// 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.
+
+import 'package:front_end/src/base/libraries_spec.dart';
+import 'package:test/test.dart';
+
+main() {
+ group('parse', () {
+ test('patches are optional in the format', () async {
+ var jsonString = '''
+ { "none": { "libraries": {"c" : { "path": "c/main.dart" }}}}
+ ''';
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
ahe 2017/08/03 11:58:16 YAY!!! \o/ :-D Use three slashes so "one" isn't i
Siggi Cherem (dart-lang) 2017/08/05 00:41:02 Done.
+ expect(spec, isNotNull);
+ expect(
+ spec.specificationFor('none').libraryInfoFor('c').patches, isEmpty);
+ });
+
+ test('library paths are resolved from spec uri', () async {
+ var jsonString = '''
+ { "none": { "libraries": {"c" : { "path": "c/main.dart" }}}}
+ ''';
+
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
+ expect(spec.specificationFor('none').libraryInfoFor('c').uri,
+ Uri.parse('org-dartlang-custom://one/two/c/main.dart'));
+ });
+
+ test('patches paths are resolved from spec uri', () async {
+ var jsonString = '''
+ {
+ "none": {
+ "libraries": {
+ "c" : {
+ "path": "c/main.dart",
+ "patches": [
+ "../a/p1.dart",
+ "../a/p2.dart"
+ ]
+ }
+ }
+ }
+ }
+ ''';
+
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
+ expect(spec.specificationFor('none').libraryInfoFor('c').patches[0],
+ Uri.parse('org-dartlang-custom://one/a/p1.dart'));
+ expect(spec.specificationFor('none').libraryInfoFor('c').patches[1],
+ Uri.parse('org-dartlang-custom://one/a/p2.dart'));
+ });
+
+ test('multiple targets are supported', () async {
+ var jsonString = '''
+ {
+ "vm": {
+ "libraries": {
+ "foo" : {
+ "path": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "path": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "path": "c/main.dart"
+ }
+ }
+ }
+ }
+ ''';
+
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
+
+ expect(spec.specificationFor('vm').libraryInfoFor('foo').uri,
+ Uri.parse('org-dartlang-custom://one/two/a/main.dart'));
+ expect(spec.specificationFor('vm').libraryInfoFor('bar').uri,
+ Uri.parse('org-dartlang-custom://one/two/b/main.dart'));
+ expect(spec.specificationFor('none').libraryInfoFor('c').uri,
+ Uri.parse('org-dartlang-custom://one/two/c/main.dart'));
+ });
+ });
+
+ group('toJson', () {
+ test('serialization produces same data that was parsed', () async {
+ var jsonString = '''
+ {
+ "vm": {
+ "libraries": {
+ "foo" : {
+ "path": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "path": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "path": "c/main.dart",
+ "patches": []
+ }
+ }
+ }
+ }
+ ''';
+
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
+ var newJson =
+ spec.toJsonString(Uri.parse('org-dartlang-custom://one/two/g.json'));
+ expect(jsonString.replaceAll(new RegExp('\\s'), ''), newJson);
+ });
+
+ test('serialization can adapt to new file location', () async {
+ var jsonString = '''
+ {
+ "vm": {
+ "libraries": {
+ "foo" : {
+ "path": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "path": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "path": "c/main.dart"
+ }
+ }
+ }
+ }
+ ''';
+
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString);
+ var newJson =
+ spec.toJsonString(Uri.parse('org-dartlang-custom://one/g.json'));
+
+ var expected = '''
+ {
+ "vm": {
+ "libraries": {
+ "foo" : {
+ "path": "two/a/main.dart",
+ "patches": [
+ "two/a/p1.dart",
+ "two/a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "path": "two/b/main.dart",
+ "patches": [
+ "two/b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "path": "two/c/main.dart",
+ "patches": []
+ }
+ }
+ }
+ }
+ ''';
+
+ expect(expected.replaceAll(new RegExp('\\s'), ''), newJson);
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698