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

Unified Diff: test/parser_test.dart

Issue 2560623003: Support a new source map bundle format useful for the Dart Dev Compiler. A source map bundle is a J… (Closed)
Patch Set: Improve handling of locations not from the uris the source map is for. Make `MappingBundle` disting… Created 4 years 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 | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/parser_test.dart
diff --git a/test/parser_test.dart b/test/parser_test.dart
index 88da8c54740c707fbf42734b72588fd5eb0eb97d..a317f7e6370382578ba75a645a78f34b972c83df 100644
--- a/test/parser_test.dart
+++ b/test/parser_test.dart
@@ -7,35 +7,59 @@ library test.parser_test;
import 'dart:convert';
import 'package:test/test.dart';
import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
import 'common.dart';
const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const {
- 'version': 3,
- 'sourceRoot': '',
- 'sources': const ['input.dart'],
- 'names': const [],
- 'mappings': 'A',
- 'file': 'output.dart'
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const [],
+ 'mappings': 'A',
+ 'file': 'output.dart'
};
const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const {
- 'version': 3,
- 'sourceRoot': '',
- 'sources': const ['input.dart'],
- 'names': const [],
- 'mappings': 'AAAA',
- 'file': 'output.dart'
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const [],
+ 'mappings': 'AAAA',
+ 'file': 'output.dart'
};
const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const {
- 'version': 3,
- 'sourceRoot': '',
- 'sources': const ['input.dart'],
- 'names': const ['var'],
- 'mappings': 'AAAAA',
- 'file': 'output.dart'
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const ['var'],
+ 'mappings': 'AAAAA',
+ 'file': 'output.dart'
};
+const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_1 = const {
+ 'version': 3,
+ 'sourceRoot': 'pkg/',
+ 'sources': const ['input1.dart'],
+ 'names': const ['var1'],
+ 'mappings': 'AAAAA',
+ 'file': 'output1.dart'
+};
+
+const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_2 = const {
+ 'version': 3,
+ 'sourceRoot': 'pkg/',
+ 'sources': const ['input2.dart'],
+ 'names': const ['var2'],
+ 'mappings': 'AAAAA',
+ 'file': 'output2.dart'
+};
+
+const List SOURCE_MAP_BUNDLE = const [
+ MAP_WITH_SOURCE_LOCATION_AND_NAME_1,
+ MAP_WITH_SOURCE_LOCATION_AND_NAME_2
+];
+
main() {
test('parse', () {
var mapping = parseJson(EXPECTED_MAP);
@@ -105,6 +129,12 @@ main() {
inputMap['sourceRoot'] = '/pkg/';
var mapping = parseJson(inputMap);
expect(mapping.spanFor(0, 0).sourceUrl, Uri.parse("/pkg/input.dart"));
+ expect(
+ mapping
+ .spanForLocation(
+ new SourceLocation(0, sourceUrl: Uri.parse("ignored.dart")))
+ .sourceUrl,
+ Uri.parse("/pkg/input.dart"));
var newSourceRoot = '/new/';
@@ -122,14 +152,107 @@ main() {
Uri.parse("file:///path/to/pkg/input.dart"));
});
+ group('parse with bundle', () {
+ var mapping =
+ parseJsonExtended(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map");
+ test('simple', () {
+ expect(
+ mapping
+ .spanForLocation(new SourceLocation(0,
+ sourceUrl: new Uri.file('/path/to/output1.dart')))
+ .sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(
+ mapping
+ .spanForLocation(new SourceLocation(0,
+ sourceUrl: new Uri.file('/path/to/output2.dart')))
+ .sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+
+ expect(
+ mapping.spanFor(0, 0, uri: "file:///path/to/output1.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(
+ mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+ });
+
+ test('unmapped path', () {
+ var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart");
+ expect(span.sourceUrl, Uri.parse("unmapped_output.dart"));
+ expect(span.start.line, equals(0));
+ expect(span.start.column, equals(0));
+
+ span = mapping.spanFor(10, 5, uri: "unmapped_output.dart");
+ expect(span.sourceUrl, Uri.parse("unmapped_output.dart"));
+ expect(span.start.line, equals(10));
+ expect(span.start.column, equals(5));
+ });
+
+ test('missing path', () {
+ expect(() => mapping.spanFor(0, 0), throws);
+ });
+
+ test('incomplete paths', () {
+ expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+ });
+
+ test('parseExtended', () {
+ var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE),
+ mapUrl: "file:///path/to/map");
+
+ expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+ });
+
+ // Test that the source map can handle cases where the uri passed in is
+ // not from the expected host but it is still unambiguous which source
+ // map should be used.
+ test('different paths', () {
+ expect(
+ mapping
+ .spanForLocation(new SourceLocation(0,
+ sourceUrl: Uri.parse('http://localhost/output1.dart')))
+ .sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(
+ mapping
+ .spanForLocation(new SourceLocation(0,
+ sourceUrl: Uri.parse('http://localhost/output2.dart')))
+ .sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+
+ expect(
+ mapping.spanFor(0, 0, uri: "http://localhost/output1.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input1.dart"));
+ expect(
+ mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl,
+ Uri.parse("file:///path/to/pkg/input2.dart"));
+ });
+ });
+
test('parse and re-emit', () {
for (var expected in [
- EXPECTED_MAP,
- MAP_WITH_NO_SOURCE_LOCATION,
- MAP_WITH_SOURCE_LOCATION,
- MAP_WITH_SOURCE_LOCATION_AND_NAME]) {
+ EXPECTED_MAP,
+ MAP_WITH_NO_SOURCE_LOCATION,
+ MAP_WITH_SOURCE_LOCATION,
+ MAP_WITH_SOURCE_LOCATION_AND_NAME
+ ]) {
var mapping = parseJson(expected);
expect(mapping.toJson(), equals(expected));
+
+ mapping = parseJsonExtended(expected);
+ expect(mapping.toJson(), equals(expected));
}
+ // Invalid for this case
+ expect(() => parseJson(SOURCE_MAP_BUNDLE), throws);
+
+ var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE);
+ expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE));
});
}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698