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 'package:source_span/source_span.dart'; | |
| 10 import 'common.dart'; | 11 import 'common.dart'; |
| 11 | 12 |
| 12 const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const { | 13 const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const { |
| 13 'version': 3, | 14 'version': 3, |
| 14 'sourceRoot': '', | 15 'sourceRoot': '', |
| 15 'sources': const ['input.dart'], | 16 'sources': const ['input.dart'], |
| 16 'names': const [], | 17 'names': const [], |
| 17 'mappings': 'A', | 18 'mappings': 'A', |
| 18 'file': 'output.dart' | 19 'file': 'output.dart' |
| 19 }; | 20 }; |
| 20 | 21 |
| 21 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const { | 22 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const { |
| 22 'version': 3, | 23 'version': 3, |
| 23 'sourceRoot': '', | 24 'sourceRoot': '', |
| 24 'sources': const ['input.dart'], | 25 'sources': const ['input.dart'], |
| 25 'names': const [], | 26 'names': const [], |
| 26 'mappings': 'AAAA', | 27 'mappings': 'AAAA', |
| 27 'file': 'output.dart' | 28 'file': 'output.dart' |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const { | 31 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const { |
| 31 'version': 3, | 32 'version': 3, |
| 32 'sourceRoot': '', | 33 'sourceRoot': '', |
| 33 'sources': const ['input.dart'], | 34 'sources': const ['input.dart'], |
| 34 'names': const ['var'], | 35 'names': const ['var'], |
| 35 'mappings': 'AAAAA', | 36 'mappings': 'AAAAA', |
| 36 'file': 'output.dart' | 37 'file': 'output.dart' |
| 37 }; | 38 }; |
| 38 | 39 |
| 40 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_1 = const { | |
| 41 'version': 3, | |
| 42 'sourceRoot': 'pkg/', | |
| 43 'sources': const ['input1.dart'], | |
| 44 'names': const ['var1'], | |
| 45 'mappings': 'AAAAA', | |
| 46 'file': 'output1.dart' | |
| 47 }; | |
| 48 | |
| 49 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME_2 = const { | |
| 50 'version': 3, | |
| 51 'sourceRoot': 'pkg/', | |
| 52 'sources': const ['input2.dart'], | |
| 53 'names': const ['var2'], | |
| 54 'mappings': 'AAAAA', | |
| 55 'file': 'output2.dart' | |
| 56 }; | |
| 57 | |
| 58 const List SOURCE_MAP_BUNDLE = const [ | |
| 59 MAP_WITH_SOURCE_LOCATION_AND_NAME_1, | |
| 60 MAP_WITH_SOURCE_LOCATION_AND_NAME_2 | |
| 61 ]; | |
| 62 | |
| 39 main() { | 63 main() { |
| 40 test('parse', () { | 64 test('parse', () { |
| 41 var mapping = parseJson(EXPECTED_MAP); | 65 var mapping = parseJson(EXPECTED_MAP); |
| 42 check(outputVar1, mapping, inputVar1, false); | 66 check(outputVar1, mapping, inputVar1, false); |
| 43 check(outputVar2, mapping, inputVar2, false); | 67 check(outputVar2, mapping, inputVar2, false); |
| 44 check(outputFunction, mapping, inputFunction, false); | 68 check(outputFunction, mapping, inputFunction, false); |
| 45 check(outputExpr, mapping, inputExpr, false); | 69 check(outputExpr, mapping, inputExpr, false); |
| 46 }); | 70 }); |
| 47 | 71 |
| 48 test('parse + json', () { | 72 test('parse + json', () { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 expect(entry.sourceColumn, 0); | 122 expect(entry.sourceColumn, 0); |
| 99 expect(entry.sourceLine, 0); | 123 expect(entry.sourceLine, 0); |
| 100 expect(entry.sourceNameId, 0); | 124 expect(entry.sourceNameId, 0); |
| 101 }); | 125 }); |
| 102 | 126 |
| 103 test('parse with source root', () { | 127 test('parse with source root', () { |
| 104 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); | 128 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
| 105 inputMap['sourceRoot'] = '/pkg/'; | 129 inputMap['sourceRoot'] = '/pkg/'; |
| 106 var mapping = parseJson(inputMap); | 130 var mapping = parseJson(inputMap); |
| 107 expect(mapping.spanFor(0, 0).sourceUrl, Uri.parse("/pkg/input.dart")); | 131 expect(mapping.spanFor(0, 0).sourceUrl, Uri.parse("/pkg/input.dart")); |
| 132 expect( | |
| 133 mapping | |
| 134 .spanForLocation( | |
| 135 new SourceLocation(0, sourceUrl: Uri.parse("ignored.dart"))) | |
| 136 .sourceUrl, | |
| 137 Uri.parse("/pkg/input.dart")); | |
| 108 | 138 |
| 109 var newSourceRoot = '/new/'; | 139 var newSourceRoot = '/new/'; |
| 110 | 140 |
| 111 mapping.sourceRoot = newSourceRoot; | 141 mapping.sourceRoot = newSourceRoot; |
| 112 inputMap["sourceRoot"] = newSourceRoot; | 142 inputMap["sourceRoot"] = newSourceRoot; |
| 113 | 143 |
| 114 expect(mapping.toJson(), equals(inputMap)); | 144 expect(mapping.toJson(), equals(inputMap)); |
| 115 }); | 145 }); |
| 116 | 146 |
| 117 test('parse with map URL', () { | 147 test('parse with map URL', () { |
| 118 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); | 148 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
| 119 inputMap['sourceRoot'] = 'pkg/'; | 149 inputMap['sourceRoot'] = 'pkg/'; |
| 120 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); | 150 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); |
| 121 expect(mapping.spanFor(0, 0).sourceUrl, | 151 expect(mapping.spanFor(0, 0).sourceUrl, |
| 122 Uri.parse("file:///path/to/pkg/input.dart")); | 152 Uri.parse("file:///path/to/pkg/input.dart")); |
| 123 }); | 153 }); |
| 124 | 154 |
| 155 group('parse with bundle', () { | |
| 156 var mapping = | |
| 157 parseJsonExtended(SOURCE_MAP_BUNDLE, mapUrl: "file:///path/to/map"); | |
| 158 test('simple', () { | |
| 159 expect( | |
| 160 mapping | |
| 161 .spanForLocation(new SourceLocation(0, | |
| 162 sourceUrl: new Uri.file('/path/to/output1.dart'))) | |
| 163 .sourceUrl, | |
| 164 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 165 expect( | |
| 166 mapping | |
| 167 .spanForLocation(new SourceLocation(0, | |
| 168 sourceUrl: new Uri.file('/path/to/output2.dart'))) | |
| 169 .sourceUrl, | |
| 170 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 171 | |
| 172 expect( | |
| 173 mapping.spanFor(0, 0, uri: "file:///path/to/output1.dart").sourceUrl, | |
| 174 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 175 expect( | |
| 176 mapping.spanFor(0, 0, uri: "file:///path/to/output2.dart").sourceUrl, | |
| 177 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 178 }); | |
| 179 | |
| 180 test('missing path', () { | |
| 181 expect(mapping.spanFor(0, 0, uri: "wrong_output.dart"), isNull); | |
|
Siggi Cherem (dart-lang)
2016/12/07 23:27:00
let's include a test with 'null' :)
Jacob
2016/12/08 16:20:21
Done.
| |
| 182 }); | |
| 183 | |
| 184 test('incomplete paths', () { | |
| 185 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | |
| 186 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 187 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | |
| 188 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 189 }); | |
| 190 | |
| 191 test('parseExtended', () { | |
| 192 var mapping = parseExtended(JSON.encode(SOURCE_MAP_BUNDLE), | |
| 193 mapUrl: "file:///path/to/map"); | |
| 194 | |
| 195 expect(mapping.spanFor(0, 0, uri: "output1.dart").sourceUrl, | |
| 196 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 197 expect(mapping.spanFor(0, 0, uri: "output2.dart").sourceUrl, | |
| 198 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 199 }); | |
| 200 | |
| 201 // Test that the source map can handle cases where the uri passed in is | |
| 202 // not from the expected host but it is still unambiguous which source | |
| 203 // map should be used. | |
| 204 test('different paths', () { | |
| 205 expect( | |
| 206 mapping | |
| 207 .spanForLocation(new SourceLocation(0, | |
| 208 sourceUrl: Uri.parse('http://localhost/output1.dart'))) | |
| 209 .sourceUrl, | |
| 210 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 211 expect( | |
| 212 mapping | |
| 213 .spanForLocation(new SourceLocation(0, | |
| 214 sourceUrl: Uri.parse('http://localhost/output2.dart'))) | |
| 215 .sourceUrl, | |
| 216 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 217 | |
| 218 expect( | |
| 219 mapping.spanFor(0, 0, uri: "http://localhost/output1.dart").sourceUrl, | |
| 220 Uri.parse("file:///path/to/pkg/input1.dart")); | |
| 221 expect( | |
| 222 mapping.spanFor(0, 0, uri: "http://localhost/output2.dart").sourceUrl, | |
| 223 Uri.parse("file:///path/to/pkg/input2.dart")); | |
| 224 }); | |
| 225 }); | |
| 226 | |
| 125 test('parse and re-emit', () { | 227 test('parse and re-emit', () { |
| 126 for (var expected in [ | 228 for (var expected in [ |
| 127 EXPECTED_MAP, | 229 EXPECTED_MAP, |
| 128 MAP_WITH_NO_SOURCE_LOCATION, | 230 MAP_WITH_NO_SOURCE_LOCATION, |
| 129 MAP_WITH_SOURCE_LOCATION, | 231 MAP_WITH_SOURCE_LOCATION, |
| 130 MAP_WITH_SOURCE_LOCATION_AND_NAME]) { | 232 MAP_WITH_SOURCE_LOCATION_AND_NAME |
| 233 ]) { | |
| 131 var mapping = parseJson(expected); | 234 var mapping = parseJson(expected); |
| 132 expect(mapping.toJson(), equals(expected)); | 235 expect(mapping.toJson(), equals(expected)); |
| 236 | |
| 237 mapping = parseJsonExtended(expected); | |
| 238 expect(mapping.toJson(), equals(expected)); | |
| 133 } | 239 } |
| 240 // Invalid for this case | |
| 241 expect(() => parseJson(SOURCE_MAP_BUNDLE), throws); | |
| 242 | |
| 243 var mapping = parseJsonExtended(SOURCE_MAP_BUNDLE); | |
| 244 expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE)); | |
| 134 }); | 245 }); |
| 135 } | 246 } |
| OLD | NEW |