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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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"); |
158 test('simple', () { | 168 test('simple', () { |
159 expect( | 169 expect( |
160 mapping | 170 mapping |
161 .spanForLocation(new SourceLocation(0, | 171 .spanForLocation(new SourceLocation(0, |
162 sourceUrl: new Uri.file('/path/to/output1.dart'))) | 172 sourceUrl: new Uri.file('/path/to/output.dart'))) |
163 .sourceUrl, | 173 .sourceUrl, |
164 Uri.parse("file:///path/to/pkg/input1.dart")); | 174 Uri.parse("file:///path/to/pkg/input1.dart")); |
165 expect( | 175 expect( |
166 mapping | 176 mapping |
167 .spanForLocation(new SourceLocation(0, | 177 .spanForLocation(new SourceLocation(0, |
168 sourceUrl: new Uri.file('/path/to/output2.dart'))) | 178 sourceUrl: new Uri.file('/path/to/output2.dart'))) |
169 .sourceUrl, | 179 .sourceUrl, |
170 Uri.parse("file:///path/to/pkg/input2.dart")); | 180 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 181 expect( |
| 182 mapping |
| 183 .spanForLocation(new SourceLocation(0, |
| 184 sourceUrl: new Uri.file('/path/to/3/output.dart'))) |
| 185 .sourceUrl, |
| 186 Uri.parse("file:///path/to/pkg/input3.dart")); |
171 | 187 |
172 expect( | 188 expect( |
173 mapping.spanFor(0, 0, uri: "file:///path/to/output1.dart").sourceUrl, | 189 mapping.spanFor(0, 0, uri: "file:///path/to/output.dart").sourceUrl, |
174 Uri.parse("file:///path/to/pkg/input1.dart")); | 190 Uri.parse("file:///path/to/pkg/input1.dart")); |
175 expect( | 191 expect( |
176 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, | 192 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, |
177 Uri.parse("file:///path/to/pkg/input2.dart")); | 193 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 194 expect( |
| 195 mapping.spanFor(0, 0, uri: "file:///path/to/3/output.dart").sourceUrl, |
| 196 Uri.parse("file:///path/to/pkg/input3.dart")); |
178 }); | 197 }); |
179 | 198 |
180 test('unmapped path', () { | 199 test('unmapped path', () { |
181 var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart"); | 200 var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart"); |
182 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); | 201 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); |
183 expect(span.start.line, equals(0)); | 202 expect(span.start.line, equals(0)); |
184 expect(span.start.column, equals(0)); | 203 expect(span.start.column, equals(0)); |
185 | 204 |
186 span = mapping.spanFor(10, 5, uri: "unmapped_output.dart"); | 205 span = mapping.spanFor(10, 5, uri: "unmapped_output.dart"); |
187 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); | 206 expect(span.sourceUrl, Uri.parse("unmapped_output.dart")); |
188 expect(span.start.line, equals(10)); | 207 expect(span.start.line, equals(10)); |
189 expect(span.start.column, equals(5)); | 208 expect(span.start.column, equals(5)); |
190 }); | 209 }); |
191 | 210 |
192 test('missing path', () { | 211 test('missing path', () { |
193 expect(() => mapping.spanFor(0, 0), throws); | 212 expect(() => mapping.spanFor(0, 0), throws); |
194 }); | 213 }); |
195 | 214 |
196 test('incomplete paths', () { | 215 test('incomplete paths', () { |
197 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | 216 expect(mapping.spanFor(0, 0, uri: "output.dart").sourceUrl, |
198 Uri.parse("file:///path/to/pkg/input1.dart")); | 217 Uri.parse("file:///path/to/pkg/input1.dart")); |
199 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | 218 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, |
200 Uri.parse("file:///path/to/pkg/input2.dart")); | 219 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 220 expect(mapping.spanFor(0, 0, uri: "3/output.dart").sourceUrl, |
| 221 Uri.parse("file:///path/to/pkg/input3.dart")); |
201 }); | 222 }); |
202 | 223 |
203 test('parseExtended', () { | 224 test('parseExtended', () { |
204 var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE), | 225 var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE), |
205 mapUrl: "file:///path/to/map"); | 226 mapUrl: "file:///path/to/map"); |
206 | 227 |
207 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | 228 expect(mapping.spanFor(0, 0, uri: "output.dart").sourceUrl, |
208 Uri.parse("file:///path/to/pkg/input1.dart")); | 229 Uri.parse("file:///path/to/pkg/input1.dart")); |
209 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | 230 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, |
210 Uri.parse("file:///path/to/pkg/input2.dart")); | 231 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 232 expect(mapping.spanFor(0, 0, uri: "3/output.dart").sourceUrl, |
| 233 Uri.parse("file:///path/to/pkg/input3.dart")); |
211 }); | 234 }); |
212 | 235 |
213 // Test that the source map can handle cases where the uri passed in is | 236 // 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 | 237 // not from the expected host but it is still unambiguous which source |
215 // map should be used. | 238 // map should be used. |
216 test('different paths', () { | 239 test('different paths', () { |
217 expect( | 240 expect( |
218 mapping | 241 mapping |
219 .spanForLocation(new SourceLocation(0, | 242 .spanForLocation(new SourceLocation(0, |
220 sourceUrl: Uri.parse('http://localhost/output1.dart'))) | 243 sourceUrl: Uri.parse('http://localhost/output.dart'))) |
221 .sourceUrl, | 244 .sourceUrl, |
222 Uri.parse("file:///path/to/pkg/input1.dart")); | 245 Uri.parse("file:///path/to/pkg/input1.dart")); |
223 expect( | 246 expect( |
224 mapping | 247 mapping |
225 .spanForLocation(new SourceLocation(0, | 248 .spanForLocation(new SourceLocation(0, |
226 sourceUrl: Uri.parse('http://localhost/output2.dart'))) | 249 sourceUrl: Uri.parse('http://localhost/output2.dart'))) |
227 .sourceUrl, | 250 .sourceUrl, |
228 Uri.parse("file:///path/to/pkg/input2.dart")); | 251 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 252 expect( |
| 253 mapping |
| 254 .spanForLocation(new SourceLocation(0, |
| 255 sourceUrl: Uri.parse('http://localhost/3/output.dart'))) |
| 256 .sourceUrl, |
| 257 Uri.parse("file:///path/to/pkg/input3.dart")); |
229 | 258 |
230 expect( | 259 expect( |
231 mapping.spanFor(0, 0, uri: "http://localhost/output1.dart").sourceUrl, | 260 mapping.spanFor(0, 0, uri: "http://localhost/output.dart").sourceUrl, |
232 Uri.parse("file:///path/to/pkg/input1.dart")); | 261 Uri.parse("file:///path/to/pkg/input1.dart")); |
233 expect( | 262 expect( |
234 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, | 263 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, |
235 Uri.parse("file:///path/to/pkg/input2.dart")); | 264 Uri.parse("file:///path/to/pkg/input2.dart")); |
| 265 expect( |
| 266 mapping |
| 267 .spanFor(0, 0, uri: "http://localhost/3/output.dart") |
| 268 .sourceUrl, |
| 269 Uri.parse("file:///path/to/pkg/input3.dart")); |
236 }); | 270 }); |
237 }); | 271 }); |
238 | 272 |
239 test('parse and re-emit', () { | 273 test('parse and re-emit', () { |
240 for (var expected in [ | 274 for (var expected in [ |
241 EXPECTED_MAP, | 275 EXPECTED_MAP, |
242 MAP_WITH_NO_SOURCE_LOCATION, | 276 MAP_WITH_NO_SOURCE_LOCATION, |
243 MAP_WITH_SOURCE_LOCATION, | 277 MAP_WITH_SOURCE_LOCATION, |
244 MAP_WITH_SOURCE_LOCATION_AND_NAME | 278 MAP_WITH_SOURCE_LOCATION_AND_NAME |
245 ]) { | 279 ]) { |
246 var mapping = parseJson(expected); | 280 var mapping = parseJson(expected); |
247 expect(mapping.toJson(), equals(expected)); | 281 expect(mapping.toJson(), equals(expected)); |
248 | 282 |
249 mapping = parseJsonExtended(expected); | 283 mapping = parseJsonExtended(expected); |
250 expect(mapping.toJson(), equals(expected)); | 284 expect(mapping.toJson(), equals(expected)); |
251 } | 285 } |
252 // Invalid for this case | 286 // Invalid for this case |
253 expect(() => parseJson(SOURCE_MAP_BUNDLE as dynamic), throws); | 287 expect(() => parseJson(SOURCE_MAP_BUNDLE as dynamic), throws); |
254 | 288 |
255 var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE); | 289 var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE); |
256 expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE)); | 290 expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE)); |
257 }); | 291 }); |
258 } | 292 } |
OLD | NEW |