Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.parser_test; | 5 library test.parser_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 import 'package:source_maps/source_maps.dart'; | 9 import 'package:source_maps/source_maps.dart'; |
| 10 import 'common.dart'; | 10 import 'common.dart'; |
| 11 | 11 |
| 12 const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const { | 12 const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const { |
| 13 'version': 3, | 13 'version': 3, |
| 14 'sourceRoot': '', | 14 'sourceRoot': '', |
| 15 'sources': const ['input.dart'], | 15 'sources': const ['input.dart'], |
| 16 'names': const [], | 16 'names': const [], |
| 17 'mappings': 'A', | 17 'mappings': 'A', |
| 18 'file': 'output.dart' | 18 'file': 'output.dart' |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const { | 21 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const { |
| 22 'version': 3, | 22 'version': 3, |
| 23 'sourceRoot': '', | 23 'sourceRoot': '', |
| 24 'sources': const ['input.dart'], | 24 'sources': const ['input.dart'], |
| 25 'names': const [], | 25 'names': const [], |
| 26 'mappings': 'AAAA', | 26 'mappings': 'AAAA', |
| 27 'file': 'output.dart' | 27 'file': 'output.dart' |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const { | 30 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const { |
| 31 'version': 3, | 31 'version': 3, |
| 32 'sourceRoot': '', | 32 'sourceRoot': '', |
| 33 'sources': const ['input.dart'], | 33 'sources': const ['input.dart'], |
| 34 'names': const ['var'], | 34 'names': const ['var'], |
| 35 'mappings': 'AAAAA', | 35 'mappings': 'AAAAA', |
| 36 'file': 'output.dart' | 36 'file': 'output.dart' |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_1 = const { | |
| 40 'version': 3, | |
| 41 'sourceRoot': 'pkg/', | |
| 42 'sources': const ['input1.dart'], | |
| 43 'names': const ['var1'], | |
| 44 'mappings': 'AAAAA', | |
| 45 'file': 'output1.dart' | |
| 46 }; | |
| 47 | |
| 48 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_2 = const { | |
| 49 'version': 3, | |
| 50 'sourceRoot': 'pkg/', | |
| 51 'sources': const ['input2.dart'], | |
| 52 'names': const ['var2'], | |
| 53 'mappings': 'AAAAA', | |
| 54 'file': 'output2.dart' | |
| 55 }; | |
| 56 | |
| 57 const List SOURCE_MAP_BUNDLE = const [ | |
| 58 MAP_WITH_SOURCE_LOCATION_AND_NAME_1, | |
| 59 MAP_WITH_SOURCE_LOCATION_AND_NAME_2 | |
| 60 ]; | |
| 61 | |
| 39 main() { | 62 main() { |
| 40 test('parse', () { | 63 test('parse', () { |
| 41 var mapping = parseJson(EXPECTED_MAP); | 64 var mapping = parseJson(EXPECTED_MAP); |
| 42 check(outputVar1, mapping, inputVar1, false); | 65 check(outputVar1, mapping, inputVar1, false); |
| 43 check(outputVar2, mapping, inputVar2, false); | 66 check(outputVar2, mapping, inputVar2, false); |
| 44 check(outputFunction, mapping, inputFunction, false); | 67 check(outputFunction, mapping, inputFunction, false); |
| 45 check(outputExpr, mapping, inputExpr, false); | 68 check(outputExpr, mapping, inputExpr, false); |
| 46 }); | 69 }); |
| 47 | 70 |
| 48 test('parse + json', () { | 71 test('parse + json', () { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 }); | 138 }); |
| 116 | 139 |
| 117 test('parse with map URL', () { | 140 test('parse with map URL', () { |
| 118 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); | 141 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
| 119 inputMap['sourceRoot'] = 'pkg/'; | 142 inputMap['sourceRoot'] = 'pkg/'; |
| 120 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); | 143 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); |
| 121 expect(mapping.spanFor(0, 0).sourceUrl, | 144 expect(mapping.spanFor(0, 0).sourceUrl, |
| 122 Uri.parse("file:///path/to/pkg/input.dart")); | 145 Uri.parse("file:///path/to/pkg/input.dart")); |
| 123 }); | 146 }); |
| 124 | 147 |
| 148 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.
| |
| 149 var mapping = parseJson(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map"); | |
| 150 test('simple', () { | |
| 151 expect( | |
| 152 mapping.spanFor(0, 0, uri: "file:///path/to/output1.dart").sourceUrl, | |
| 153 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 154 expect( | |
| 155 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, | |
| 156 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 157 }); | |
| 158 | |
| 159 test('missing path', () { | |
| 160 expect(mapping.spanFor(0, 0, uri: "wrong_output.dart"), isNull); | |
| 161 }); | |
| 162 | |
| 163 test('incomplete paths', () { | |
| 164 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | |
| 165 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 166 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | |
| 167 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 168 }); | |
| 169 | |
| 170 // Test that the source map can handle cases where the uri passed in is | |
| 171 // not from the expected host but it is still unambiguous which source | |
| 172 // map should be used. | |
| 173 test('different paths', () { | |
| 174 expect( | |
| 175 mapping.spanFor(0, 0, uri: "http://localhost/output1.dart").sourceUrl, | |
| 176 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 177 expect( | |
| 178 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, | |
| 179 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 180 }); | |
| 181 }); | |
| 182 | |
| 125 test('parse and re-emit', () { | 183 test('parse and re-emit', () { |
| 126 for (var expected in [ | 184 for (var expected in [ |
| 127 EXPECTED_MAP, | 185 EXPECTED_MAP, |
| 128 MAP_WITH_NO_SOURCE_LOCATION, | 186 MAP_WITH_NO_SOURCE_LOCATION, |
| 129 MAP_WITH_SOURCE_LOCATION, | 187 MAP_WITH_SOURCE_LOCATION, |
| 130 MAP_WITH_SOURCE_LOCATION_AND_NAME]) { | 188 MAP_WITH_SOURCE_LOCATION_AND_NAME, |
| 189 SOURCE_MAP_BUNDLE | |
| 190 ]) { | |
| 131 var mapping = parseJson(expected); | 191 var mapping = parseJson(expected); |
| 132 expect(mapping.toJson(), equals(expected)); | 192 expect(mapping.toJson(), equals(expected)); |
| 133 } | 193 } |
| 134 }); | 194 }); |
| 135 } | 195 } |
| OLD | NEW |