OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.parser_test; |
| 6 |
| 7 import 'dart:convert'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 import 'package:source_maps/source_maps.dart'; |
| 10 import 'common.dart'; |
| 11 |
| 12 const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const { |
| 13 'version': 3, |
| 14 'sourceRoot': '', |
| 15 'sources': const ['input.dart'], |
| 16 'names': const [], |
| 17 'mappings': 'A', |
| 18 'file': 'output.dart' |
| 19 }; |
| 20 |
| 21 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const { |
| 22 'version': 3, |
| 23 'sourceRoot': '', |
| 24 'sources': const ['input.dart'], |
| 25 'names': const [], |
| 26 'mappings': 'AAAA', |
| 27 'file': 'output.dart' |
| 28 }; |
| 29 |
| 30 const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const { |
| 31 'version': 3, |
| 32 'sourceRoot': '', |
| 33 'sources': const ['input.dart'], |
| 34 'names': const ['var'], |
| 35 'mappings': 'AAAAA', |
| 36 'file': 'output.dart' |
| 37 }; |
| 38 |
| 39 main() { |
| 40 test('parse', () { |
| 41 var mapping = parseJson(EXPECTED_MAP); |
| 42 check(outputVar1, mapping, inputVar1, false); |
| 43 check(outputVar2, mapping, inputVar2, false); |
| 44 check(outputFunction, mapping, inputFunction, false); |
| 45 check(outputExpr, mapping, inputExpr, false); |
| 46 }); |
| 47 |
| 48 test('parse + json', () { |
| 49 var mapping = parse(JSON.encode(EXPECTED_MAP)); |
| 50 check(outputVar1, mapping, inputVar1, false); |
| 51 check(outputVar2, mapping, inputVar2, false); |
| 52 check(outputFunction, mapping, inputFunction, false); |
| 53 check(outputExpr, mapping, inputExpr, false); |
| 54 }); |
| 55 |
| 56 test('parse with file', () { |
| 57 var mapping = parseJson(EXPECTED_MAP); |
| 58 check(outputVar1, mapping, inputVar1, true); |
| 59 check(outputVar2, mapping, inputVar2, true); |
| 60 check(outputFunction, mapping, inputFunction, true); |
| 61 check(outputExpr, mapping, inputExpr, true); |
| 62 }); |
| 63 |
| 64 test('parse with no source location', () { |
| 65 SingleMapping map = parse(JSON.encode(MAP_WITH_NO_SOURCE_LOCATION)); |
| 66 expect(map.lines.length, 1); |
| 67 expect(map.lines.first.entries.length, 1); |
| 68 TargetEntry entry = map.lines.first.entries.first; |
| 69 |
| 70 expect(entry.column, 0); |
| 71 expect(entry.sourceUrlId, null); |
| 72 expect(entry.sourceColumn, null); |
| 73 expect(entry.sourceLine, null); |
| 74 expect(entry.sourceNameId, null); |
| 75 }); |
| 76 |
| 77 test('parse with source location and no name', () { |
| 78 SingleMapping map = parse(JSON.encode(MAP_WITH_SOURCE_LOCATION)); |
| 79 expect(map.lines.length, 1); |
| 80 expect(map.lines.first.entries.length, 1); |
| 81 TargetEntry entry = map.lines.first.entries.first; |
| 82 |
| 83 expect(entry.column, 0); |
| 84 expect(entry.sourceUrlId, 0); |
| 85 expect(entry.sourceColumn, 0); |
| 86 expect(entry.sourceLine, 0); |
| 87 expect(entry.sourceNameId, null); |
| 88 }); |
| 89 |
| 90 test('parse with source location and name', () { |
| 91 SingleMapping map = parse(JSON.encode(MAP_WITH_SOURCE_LOCATION_AND_NAME)); |
| 92 expect(map.lines.length, 1); |
| 93 expect(map.lines.first.entries.length, 1); |
| 94 TargetEntry entry = map.lines.first.entries.first; |
| 95 |
| 96 expect(entry.sourceUrlId, 0); |
| 97 expect(entry.sourceUrlId, 0); |
| 98 expect(entry.sourceColumn, 0); |
| 99 expect(entry.sourceLine, 0); |
| 100 expect(entry.sourceNameId, 0); |
| 101 }); |
| 102 |
| 103 test('parse with source root', () { |
| 104 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
| 105 inputMap['sourceRoot'] = '/pkg/'; |
| 106 var mapping = parseJson(inputMap); |
| 107 expect(mapping.spanFor(0, 0).sourceUrl, Uri.parse("/pkg/input.dart")); |
| 108 |
| 109 var newSourceRoot = '/new/'; |
| 110 |
| 111 mapping.sourceRoot = newSourceRoot; |
| 112 inputMap["sourceRoot"] = newSourceRoot; |
| 113 |
| 114 expect(mapping.toJson(), equals(inputMap)); |
| 115 }); |
| 116 |
| 117 test('parse with map URL', () { |
| 118 var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION); |
| 119 inputMap['sourceRoot'] = 'pkg/'; |
| 120 var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map"); |
| 121 expect(mapping.spanFor(0, 0).sourceUrl, |
| 122 Uri.parse("file:///path/to/pkg/input.dart")); |
| 123 }); |
| 124 |
| 125 test('parse and re-emit', () { |
| 126 for (var expected in [ |
| 127 EXPECTED_MAP, |
| 128 MAP_WITH_NO_SOURCE_LOCATION, |
| 129 MAP_WITH_SOURCE_LOCATION, |
| 130 MAP_WITH_SOURCE_LOCATION_AND_NAME]) { |
| 131 var mapping = parseJson(expected); |
| 132 expect(mapping.toJson(), equals(expected)); |
| 133 } |
| 134 }); |
| 135 } |
OLD | NEW |