Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: packages/source_maps/test/parser_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/source_maps/test/end2end_test.dart ('k') | packages/source_maps/test/printer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/source_maps/test/parser_test.dart
diff --git a/packages/source_maps/test/parser_test.dart b/packages/source_maps/test/parser_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b14fdf4253f059c8d5df447fed2f4d0cfd7fbc6c
--- /dev/null
+++ b/packages/source_maps/test/parser_test.dart
@@ -0,0 +1,135 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.parser_test;
+
+import 'dart:convert';
+import 'package:unittest/unittest.dart';
+import 'package:source_maps/source_maps.dart';
+import 'common.dart';
+
+const Map<String, dynamic> MAP_WITH_NO_SOURCE_LOCATION = const {
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const [],
+ 'mappings': 'A',
+ 'file': 'output.dart'
+};
+
+const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION = const {
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const [],
+ 'mappings': 'AAAA',
+ 'file': 'output.dart'
+};
+
+const Map<String, dynamic> MAP_WITH_SOURCE_LOCATION_AND_NAME = const {
+ 'version': 3,
+ 'sourceRoot': '',
+ 'sources': const ['input.dart'],
+ 'names': const ['var'],
+ 'mappings': 'AAAAA',
+ 'file': 'output.dart'
+};
+
+main() {
+ test('parse', () {
+ var mapping = parseJson(EXPECTED_MAP);
+ check(outputVar1, mapping, inputVar1, false);
+ check(outputVar2, mapping, inputVar2, false);
+ check(outputFunction, mapping, inputFunction, false);
+ check(outputExpr, mapping, inputExpr, false);
+ });
+
+ test('parse + json', () {
+ var mapping = parse(JSON.encode(EXPECTED_MAP));
+ check(outputVar1, mapping, inputVar1, false);
+ check(outputVar2, mapping, inputVar2, false);
+ check(outputFunction, mapping, inputFunction, false);
+ check(outputExpr, mapping, inputExpr, false);
+ });
+
+ test('parse with file', () {
+ var mapping = parseJson(EXPECTED_MAP);
+ check(outputVar1, mapping, inputVar1, true);
+ check(outputVar2, mapping, inputVar2, true);
+ check(outputFunction, mapping, inputFunction, true);
+ check(outputExpr, mapping, inputExpr, true);
+ });
+
+ test('parse with no source location', () {
+ SingleMapping map = parse(JSON.encode(MAP_WITH_NO_SOURCE_LOCATION));
+ expect(map.lines.length, 1);
+ expect(map.lines.first.entries.length, 1);
+ TargetEntry entry = map.lines.first.entries.first;
+
+ expect(entry.column, 0);
+ expect(entry.sourceUrlId, null);
+ expect(entry.sourceColumn, null);
+ expect(entry.sourceLine, null);
+ expect(entry.sourceNameId, null);
+ });
+
+ test('parse with source location and no name', () {
+ SingleMapping map = parse(JSON.encode(MAP_WITH_SOURCE_LOCATION));
+ expect(map.lines.length, 1);
+ expect(map.lines.first.entries.length, 1);
+ TargetEntry entry = map.lines.first.entries.first;
+
+ expect(entry.column, 0);
+ expect(entry.sourceUrlId, 0);
+ expect(entry.sourceColumn, 0);
+ expect(entry.sourceLine, 0);
+ expect(entry.sourceNameId, null);
+ });
+
+ test('parse with source location and name', () {
+ SingleMapping map = parse(JSON.encode(MAP_WITH_SOURCE_LOCATION_AND_NAME));
+ expect(map.lines.length, 1);
+ expect(map.lines.first.entries.length, 1);
+ TargetEntry entry = map.lines.first.entries.first;
+
+ expect(entry.sourceUrlId, 0);
+ expect(entry.sourceUrlId, 0);
+ expect(entry.sourceColumn, 0);
+ expect(entry.sourceLine, 0);
+ expect(entry.sourceNameId, 0);
+ });
+
+ test('parse with source root', () {
+ var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION);
+ inputMap['sourceRoot'] = '/pkg/';
+ var mapping = parseJson(inputMap);
+ expect(mapping.spanFor(0, 0).sourceUrl, Uri.parse("/pkg/input.dart"));
+
+ var newSourceRoot = '/new/';
+
+ mapping.sourceRoot = newSourceRoot;
+ inputMap["sourceRoot"] = newSourceRoot;
+
+ expect(mapping.toJson(), equals(inputMap));
+ });
+
+ test('parse with map URL', () {
+ var inputMap = new Map.from(MAP_WITH_SOURCE_LOCATION);
+ inputMap['sourceRoot'] = 'pkg/';
+ var mapping = parseJson(inputMap, mapUrl: "file:///path/to/map");
+ expect(mapping.spanFor(0, 0).sourceUrl,
+ Uri.parse("file:///path/to/pkg/input.dart"));
+ });
+
+ test('parse and re-emit', () {
+ for (var expected in [
+ EXPECTED_MAP,
+ MAP_WITH_NO_SOURCE_LOCATION,
+ MAP_WITH_SOURCE_LOCATION,
+ MAP_WITH_SOURCE_LOCATION_AND_NAME]) {
+ var mapping = parseJson(expected);
+ expect(mapping.toJson(), equals(expected));
+ }
+ });
+}
« no previous file with comments | « packages/source_maps/test/end2end_test.dart ('k') | packages/source_maps/test/printer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698