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

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

Issue 2986303003: Switch FE to use the libraries.json format. (Closed)
Patch Set: fix issues found on bots 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_specification_test.dart
diff --git a/pkg/front_end/test/src/base/libraries_specification_test.dart b/pkg/front_end/test/src/base/libraries_specification_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..25c3b4ac2cfd0ab6c3824f9fa18a9ac65d84f369
--- /dev/null
+++ b/pkg/front_end/test/src/base/libraries_specification_test.dart
@@ -0,0 +1,309 @@
+// 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_specification.dart';
+import 'package:test/test.dart';
+
+main() {
+ group('parse', () {
+ test('top-level must be a map', () async {
+ var jsonString = '[]';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ jsonString = '""';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ });
+
+ test('target entry must be a map', () async {
+ var jsonString = '{"vm" : []}';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ jsonString = '{"vm" : ""}';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ });
+
+ test('library entry must exist', () async {
+ var jsonString = '{"vm" : {}}';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ });
+
+ test('library entry must be a map', () async {
+ var jsonString = '{"vm" : {"libraries": []}}';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ });
+
+ test('uri must be a string', () async {
+ var jsonString = '{"vm" : {"libraries": {"core": {"uri": 3}}}';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+ });
+
+ test('patches must be a string or list of string', () async {
+ var jsonString = '''
+ {
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "c/main.dart",
+ "patches": 3
+ }
+ }
+ }
+ }
+ ''';
+ expect(
+ () => LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString),
+ throwsA((e) => e is LibrariesSpecificationException));
+
+ jsonString = '''
+ {
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "c/main.dart",
+ "patches": "a.dart"
+ }
+ }
+ }
+ }
+ ''';
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString);
+ expect(spec.specificationFor("none").libraryInfoFor("c").patches.first,
+ Uri.parse('org-dartlang-custom:///a.dart'));
+
+ jsonString = '''
+ {
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "c/main.dart",
+ "patches": ["a.dart"]
+ }
+ }
+ }
+ }
+ ''';
+ spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///f.json'), jsonString);
+ expect(spec.specificationFor("none").libraryInfoFor("c").patches.first,
+ Uri.parse('org-dartlang-custom:///a.dart'));
+ });
+
+ test('patches are optional in the format', () async {
+ var jsonString = '''
+ { "none": { "libraries": {"c" : { "uri": "c/main.dart" }}}}
+ ''';
+ var spec = LibrariesSpecification.parse(
+ Uri.parse('org-dartlang-custom:///one/two/f.json'), jsonString);
+ 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" : { "uri": "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" : {
+ "uri": "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" : {
+ "uri": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "uri": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "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" : {
+ "uri": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "uri": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "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" : {
+ "uri": "a/main.dart",
+ "patches": [
+ "a/p1.dart",
+ "a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "uri": "b/main.dart",
+ "patches": [
+ "b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "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" : {
+ "uri": "two/a/main.dart",
+ "patches": [
+ "two/a/p1.dart",
+ "two/a/p2.dart"
+ ]
+ },
+ "bar" : {
+ "uri": "two/b/main.dart",
+ "patches": [
+ "two/b/p3.dart"
+ ]
+ }
+ }
+ },
+ "none": {
+ "libraries": {
+ "c" : {
+ "uri": "two/c/main.dart",
+ "patches": []
+ }
+ }
+ }
+ }
+ ''';
+
+ expect(expected.replaceAll(new RegExp('\\s'), ''), newJson);
+ });
+ });
+}
« no previous file with comments | « pkg/front_end/test/kernel_generator_test.dart ('k') | pkg/front_end/test/src/base/processed_options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698