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 'package:source_span/source_span.dart'; | 10 import 'package:source_span/source_span.dart'; |
(...skipping 25 matching lines...) Expand all Loading... |
36 'mappings': 'AAAAA', | 36 'mappings': 'AAAAA', |
37 'file': 'output.dart' | 37 'file': 'output.dart' |
38 }; | 38 }; |
39 | 39 |
40 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_1 = const { | 40 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_1 = const { |
41 'version': 3, | 41 'version': 3, |
42 'sourceRoot': 'pkg/', | 42 'sourceRoot': 'pkg/', |
43 'sources': const ['input1.dart'], | 43 'sources': const ['input1.dart'], |
44 'names': const ['var1'], | 44 'names': const ['var1'], |
45 'mappings': 'AAAAA', | 45 'mappings': 'AAAAA', |
46 'file': 'output1.dart' | 46 'file': 'output.dart' |
47 }; | 47 }; |
48 | 48 |
49 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_2 = const { | 49 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_2 = const { |
50 'version': 3, | 50 'version': 3, |
51 'sourceRoot': 'pkg/', | 51 'sourceRoot': 'pkg/', |
52 'sources': const ['input2.dart'], | 52 'sources': const ['input2.dart'], |
53 'names': const ['var2'], | 53 'names': const ['var2'], |
54 'mappings': 'AAAAA', | 54 'mappings': 'AAAAA', |
55 'file': 'output2.dart' | 55 'file': 'output2.dart' |
56 }; | 56 }; |
57 | 57 |
| 58 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_3 = const { |
| 59 'version': 3, |
| 60 'sourceRoot': 'pkg/', |
| 61 'sources': const ['input3.dart'], |
| 62 'names': const ['var3'], |
| 63 'mappings': 'AAAAA', |
| 64 'file': '3/output.dart' |
| 65 }; |
| 66 |
58 const List SOURCE_MAP_BUNDLE = const [ | 67 const List SOURCE_MAP_BUNDLE = const [ |
59 MAP_WITH_SOURCE_LOCATION_AND_NAME_1, | 68 MAP_WITH_SOURCE_LOCATION_AND_NAME_1, |
60 MAP_WITH_SOURCE_LOCATION_AND_NAME_2 | 69 MAP_WITH_SOURCE_LOCATION_AND_NAME_2, |
| 70 MAP_WITH_SOURCE_LOCATION_AND_NAME_3, |
61 ]; | 71 ]; |
62 | 72 |
63 main() { | 73 main() { |
64 test('parse', () { | 74 test('parse', () { |
65 var mapping = parseJson(EXPECTED_MAP); | 75 var mapping = parseJson(EXPECTED_MAP); |
66 check(outputVar1, mapping, inputVar1, false); | 76 check(outputVar1, mapping, inputVar1, false); |
67 check(outputVar2, mapping, inputVar2, false); | 77 check(outputVar2, mapping, inputVar2, false); |
68 check(outputFunction, mapping, inputFunction, false); | 78 check(outputFunction, mapping, inputFunction, false); |
69 check(outputExpr, mapping, inputExpr, false); | 79 check(outputExpr, mapping, inputExpr, false); |
70 }); | 80 }); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); | 158 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
149 inputMap['sourceRoot'] = 'pkg/'; | 159 inputMap['sourceRoot'] = 'pkg/'; |
150 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); | 160 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); |
151 expect(mapping.spanFor(0, 0).sourceUrl, | 161 expect(mapping.spanFor(0, 0).sourceUrl, |
152 Uri.parse("file:///path/to/pkg/input.dart")); | 162 Uri.parse("file:///path/to/pkg/input.dart")); |
153 }); | 163 }); |
154 | 164 |
155 group('parse with bundle', () { | 165 group('parse with bundle', () { |
156 var mapping = | 166 var mapping = |
157 parseJsonExtended(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map"); | 167 parseJsonExtended(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map"); |
| 168 |
158 test('simple', () { | 169 test('simple', () { |
159 expect( | 170 expect( |
160 mapping | 171 mapping |
161 .spanForLocation(new SourceLocation(0, | 172 .spanForLocation(new SourceLocation(0, |
162 sourceUrl: new Uri.file('/path/to/output1.dart'))) | 173 sourceUrl: new Uri.file('/path/to/output.dart'))) |
163 .sourceUrl, | 174 .sourceUrl, |
164 Uri.parse("file:///path/to/pkg/input1.dart")); | 175 Uri.parse("file:///path/to/pkg/input1.dart")); |
165 expect( | 176 expect( |
166 mapping | 177 mapping |
167 .spanForLocation(new SourceLocation(0, | 178 .spanForLocation(new SourceLocation(0, |
168 sourceUrl: new Uri.file('/path/to/output2.dart'))) | 179 sourceUrl: new Uri.file('/path/to/output2.dart'))) |
169 .sourceUrl, | 180 .sourceUrl, |
170 Uri.parse("file:///path/to/pkg/input2.dart")); | 181 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 182 expect( |
| 183 mapping |
| 184 .spanForLocation(new SourceLocation(0, |
| 185 sourceUrl: new Uri.file('/path/to/3/output.dart'))) |
| 186 .sourceUrl, |
| 187 Uri.parse("file:///path/to/pkg/input3.dart")); |
171 | 188 |
172 expect( | 189 expect( |
173 mapping.spanFor(0, 0, uri: "file:///path/to/output1.dart").sourceUrl, | 190 mapping.spanFor(0, 0, uri: "file:///path/to/output.dart").sourceUrl, |
174 Uri.parse("file:///path/to/pkg/input1.dart")); | 191 Uri.parse("file:///path/to/pkg/input1.dart")); |
175 expect( | 192 expect( |
176 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, | 193 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, |
177 Uri.parse("file:///path/to/pkg/input2.dart")); | 194 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 195 expect( |
| 196 mapping.spanFor(0, 0, uri: "file:///path/to/3/output.dart").sourceUrl, |
| 197 Uri.parse("file:///path/to/pkg/input3.dart")); |
| 198 }); |
| 199 |
| 200 test('package uris', () { |
| 201 expect( |
| 202 mapping |
| 203 .spanForLocation(new SourceLocation(0, |
| 204 sourceUrl: Uri.parse('package:1/output.dart'))) |
| 205 .sourceUrl, |
| 206 Uri.parse("file:///path/to/pkg/input1.dart")); |
| 207 expect( |
| 208 mapping |
| 209 .spanForLocation(new SourceLocation(0, |
| 210 sourceUrl: Uri.parse('package:2/output2.dart'))) |
| 211 .sourceUrl, |
| 212 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 213 expect( |
| 214 mapping |
| 215 .spanForLocation(new SourceLocation(0, |
| 216 sourceUrl: Uri.parse('package:3/output.dart'))) |
| 217 .sourceUrl, |
| 218 Uri.parse("file:///path/to/pkg/input3.dart")); |
| 219 |
| 220 expect(mapping.spanFor(0, 0, uri: "package:1/output.dart").sourceUrl, |
| 221 Uri.parse("file:///path/to/pkg/input1.dart")); |
| 222 expect(mapping.spanFor(0, 0, uri: "package:2/output2.dart").sourceUrl, |
| 223 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 224 expect(mapping.spanFor(0, 0, uri: "package:3/output.dart").sourceUrl, |
| 225 Uri.parse("file:///path/to/pkg/input3.dart")); |
178 }); | 226 }); |
179 | 227 |
180 test('unmapped path', () { | 228 test('unmapped path', () { |
181 var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart"); | 229 var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart"); |
182 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); | 230 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); |
183 expect(span.start.line, equals(0)); | 231 expect(span.start.line, equals(0)); |
184 expect(span.start.column, equals(0)); | 232 expect(span.start.column, equals(0)); |
185 | 233 |
186 span = mapping.spanFor(10, 5, uri: "unmapped_output.dart"); | 234 span = mapping.spanFor(10, 5, uri: "unmapped_output.dart"); |
187 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); | 235 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); |
188 expect(span.start.line, equals(10)); | 236 expect(span.start.line, equals(10)); |
189 expect(span.start.column, equals(5)); | 237 expect(span.start.column, equals(5)); |
190 }); | 238 }); |
191 | 239 |
192 test('missing path', () { | 240 test('missing path', () { |
193 expect(() => mapping.spanFor(0, 0), throws); | 241 expect(() => mapping.spanFor(0, 0), throws); |
194 }); | 242 }); |
195 | 243 |
196 test('incomplete paths', () { | 244 test('incomplete paths', () { |
197 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | 245 expect(mapping.spanFor(0, 0, uri: "output.dart").sourceUrl, |
198 Uri.parse("file:///path/to/pkg/input1.dart")); | 246 Uri.parse("file:///path/to/pkg/input1.dart")); |
199 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | 247 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, |
200 Uri.parse("file:///path/to/pkg/input2.dart")); | 248 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 249 expect(mapping.spanFor(0, 0, uri: "3/output.dart").sourceUrl, |
| 250 Uri.parse("file:///path/to/pkg/input3.dart")); |
201 }); | 251 }); |
202 | 252 |
203 test('parseExtended', () { | 253 test('parseExtended', () { |
204 var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE), | 254 var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE), |
205 mapUrl: "file:///path/to/map"); | 255 mapUrl: "file:///path/to/map"); |
206 | 256 |
207 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | 257 expect(mapping.spanFor(0, 0, uri: "output.dart").sourceUrl, |
208 Uri.parse("file:///path/to/pkg/input1.dart")); | 258 Uri.parse("file:///path/to/pkg/input1.dart")); |
209 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | 259 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, |
210 Uri.parse("file:///path/to/pkg/input2.dart")); | 260 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 261 expect(mapping.spanFor(0, 0, uri: "3/output.dart").sourceUrl, |
| 262 Uri.parse("file:///path/to/pkg/input3.dart")); |
211 }); | 263 }); |
212 | 264 |
213 // Test that the source map can handle cases where the uri passed in is | 265 // Test that the source map can handle cases where the uri passed in is |
214 // not from the expected host but it is still unambiguous which source | 266 // not from the expected host but it is still unambiguous which source |
215 // map should be used. | 267 // map should be used. |
216 test('different paths', () { | 268 test('different paths', () { |
217 expect( | 269 expect( |
218 mapping | 270 mapping |
219 .spanForLocation(new SourceLocation(0, | 271 .spanForLocation(new SourceLocation(0, |
220 sourceUrl: Uri.parse('http://localhost/output1.dart'))) | 272 sourceUrl: Uri.parse('http://localhost/output.dart'))) |
221 .sourceUrl, | 273 .sourceUrl, |
222 Uri.parse("file:///path/to/pkg/input1.dart")); | 274 Uri.parse("file:///path/to/pkg/input1.dart")); |
223 expect( | 275 expect( |
224 mapping | 276 mapping |
225 .spanForLocation(new SourceLocation(0, | 277 .spanForLocation(new SourceLocation(0, |
226 sourceUrl: Uri.parse('http://localhost/output2.dart'))) | 278 sourceUrl: Uri.parse('http://localhost/output2.dart'))) |
227 .sourceUrl, | 279 .sourceUrl, |
228 Uri.parse("file:///path/to/pkg/input2.dart")); | 280 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 281 expect( |
| 282 mapping |
| 283 .spanForLocation(new SourceLocation(0, |
| 284 sourceUrl: Uri.parse('http://localhost/3/output.dart'))) |
| 285 .sourceUrl, |
| 286 Uri.parse("file:///path/to/pkg/input3.dart")); |
229 | 287 |
230 expect( | 288 expect( |
231 mapping.spanFor(0, 0, uri: "http://localhost/output1.dart").sourceUrl, | 289 mapping.spanFor(0, 0, uri: "http://localhost/output.dart").sourceUrl, |
232 Uri.parse("file:///path/to/pkg/input1.dart")); | 290 Uri.parse("file:///path/to/pkg/input1.dart")); |
233 expect( | 291 expect( |
234 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, | 292 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, |
235 Uri.parse("file:///path/to/pkg/input2.dart")); | 293 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 294 expect( |
| 295 mapping |
| 296 .spanFor(0, 0, uri: "http://localhost/3/output.dart") |
| 297 .sourceUrl, |
| 298 Uri.parse("file:///path/to/pkg/input3.dart")); |
236 }); | 299 }); |
237 }); | 300 }); |
238 | 301 |
239 test('parse and re-emit', () { | 302 test('parse and re-emit', () { |
240 for (var expected in [ | 303 for (var expected in [ |
241 EXPECTED_MAP, | 304 EXPECTED_MAP, |
242 MAP_WITH_NO_SOURCE_LOCATION, | 305 MAP_WITH_NO_SOURCE_LOCATION, |
243 MAP_WITH_SOURCE_LOCATION, | 306 MAP_WITH_SOURCE_LOCATION, |
244 MAP_WITH_SOURCE_LOCATION_AND_NAME | 307 MAP_WITH_SOURCE_LOCATION_AND_NAME |
245 ]) { | 308 ]) { |
246 var mapping = parseJson(expected); | 309 var mapping = parseJson(expected); |
247 expect(mapping.toJson(), equals(expected)); | 310 expect(mapping.toJson(), equals(expected)); |
248 | 311 |
249 mapping = parseJsonExtended(expected); | 312 mapping = parseJsonExtended(expected); |
250 expect(mapping.toJson(), equals(expected)); | 313 expect(mapping.toJson(), equals(expected)); |
251 } | 314 } |
252 // Invalid for this case | 315 // Invalid for this case |
253 expect(() => parseJson(SOURCE_MAP_BUNDLE as dynamic), throws); | 316 expect(() => parseJson(SOURCE_MAP_BUNDLE as dynamic), throws); |
254 | 317 |
255 var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE); | 318 var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE); |
256 expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE)); | 319 expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE)); |
257 }); | 320 }); |
258 } | 321 } |
OLD | NEW |