Index: test/parser_test.dart |
diff --git a/test/parser_test.dart b/test/parser_test.dart |
index 88da8c54740c707fbf42734b72588fd5eb0eb97d..71a2545414a5258e9c0cf936dc7026181e1ea408 100644 |
--- a/test/parser_test.dart |
+++ b/test/parser_test.dart |
@@ -10,32 +10,55 @@ import 'package:source_maps/source_maps.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); |
@@ -122,12 +145,49 @@ main() { |
Uri.parse("file:///path/to/pkg/input.dart")); |
}); |
+ group('parse with bundle', () { |
Siggi Cherem (dart-lang)
2016/12/07 18:06:22
assuming we create bundle.dart, I'd move this test
Jacob
2016/12/07 20:40:31
Acknowledged.
|
+ var mapping = parseJson(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map"); |
+ test('simple', () { |
+ 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('missing path', () { |
+ expect(mapping.spanFor(0, 0, uri: "wrong_output.dart"), isNull); |
+ }); |
+ |
+ 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 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.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, |
+ SOURCE_MAP_BUNDLE |
+ ]) { |
var mapping = parseJson(expected); |
expect(mapping.toJson(), equals(expected)); |
} |