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

Side by Side Diff: test/source_map_stack_trace_test.dart

Issue 1115783002: Initial release. (Closed) Base URL: git@github.com:dart-lang/source_map_stack_trace.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | todo.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 import 'package:source_maps/source_maps.dart';
6 import 'package:source_span/source_span.dart';
7 import 'package:stack_trace/stack_trace.dart';
8 import 'package:source_map_stack_trace/source_map_stack_trace.dart';
9 import 'package:test/test.dart';
10
11 /// A simple [Mapping] for tests that don't need anything special.
12 final _simpleMapping = parseJson(
13 (new SourceMapBuilder()
14 ..addSpan(
15 new SourceMapSpan.identifier(
16 new SourceLocation(1,
17 line: 1, column: 3, sourceUrl: "foo.dart"),
18 "qux"),
19 new SourceSpan(
20 new SourceLocation(8, line: 5, column: 0),
21 new SourceLocation(18, line: 15, column: 0),
22 "\n" * 10)))
23 .build("foo.dart.js.map"));
24
25 void main() {
26 test("maps a JS line and column to a Dart line and span", () {
27 var trace = new Trace.parse("foo.dart.js 10:11 foo");
28 var frame = mapStackTrace(_simpleMapping, trace).frames.first;
29 expect(frame.uri, equals(Uri.parse("foo.dart")));
30
31 // These are +1 because stack_trace is 1-based whereas source_span is
32 // 0-basd.
33 expect(frame.line, equals(2));
34 expect(frame.column, equals(4));
35 });
36
37 test("ignores JS frames without line info", () {
38 var trace = new Trace.parse("""
39 foo.dart.js 10:11 foo
40 foo.dart.js bar
41 foo.dart.js 10:11 baz
42 """);
43 var frames = mapStackTrace(_simpleMapping, trace).frames;
44
45 expect(frames.length, equals(2));
46 expect(frames.first.member, equals("foo"));
47 expect(frames.last.member, equals("baz"));
48 });
49
50 test("ignores JS frames without corresponding spans", () {
51 var trace = new Trace.parse("""
52 foo.dart.js 10:11 foo
53 foo.dart.js 1:1 bar
54 foo.dart.js 10:11 baz
55 """);
56
57 var frames = mapStackTrace(_simpleMapping, trace).frames;
58
59 expect(frames.length, equals(2));
60 expect(frames.first.member, equals("foo"));
61 expect(frames.last.member, equals("baz"));
62 });
63
64 test("falls back to column 0 for unlisted column", () {
65 var trace = new Trace.parse("foo.dart.js 10 foo");
66 var builder = new SourceMapBuilder()
67 ..addSpan(
68 new SourceMapSpan.identifier(
69 new SourceLocation(1,
70 line: 1, column: 3, sourceUrl: "foo.dart"),
71 "qux"),
72 new SourceSpan(
73 new SourceLocation(8, line: 5, column: 0),
74 new SourceLocation(12, line: 9, column: 1),
75 "\n" * 4));
76
77 var mapping = parseJson(builder.build("foo.dart.js.map"));
78 var frame = mapStackTrace(mapping, trace).frames.first;
79 expect(frame.uri, equals(Uri.parse("foo.dart")));
80 expect(frame.line, equals(2));
81 expect(frame.column, equals(4));
82 });
83
84 test("uses package: URIs for frames within packageRoot", () {
85 var trace = new Trace.parse("foo.dart.js 10 foo");
86 var builder = new SourceMapBuilder()
87 ..addSpan(
88 new SourceMapSpan.identifier(
89 new SourceLocation(1,
90 line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"),
91 "qux"),
92 new SourceSpan(
93 new SourceLocation(8, line: 5, column: 0),
94 new SourceLocation(12, line: 9, column: 1),
95 "\n" * 4));
96
97 var mapping = parseJson(builder.build("foo.dart.js.map"));
98 var frame = mapStackTrace(mapping, trace, packageRoot: "packages/")
99 .frames.first;
100 expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
101 expect(frame.line, equals(2));
102 expect(frame.column, equals(4));
103 });
104
105 test("uses dart: URIs for frames within sdkRoot", () {
106 var trace = new Trace.parse("foo.dart.js 10 foo");
107 var builder = new SourceMapBuilder()
108 ..addSpan(
109 new SourceMapSpan.identifier(
110 new SourceLocation(1,
111 line: 1, column: 3, sourceUrl: "sdk/lib/async/foo.dart"),
112 "qux"),
113 new SourceSpan(
114 new SourceLocation(8, line: 5, column: 0),
115 new SourceLocation(12, line: 9, column: 1),
116 "\n" * 4));
117
118 var mapping = parseJson(builder.build("foo.dart.js.map"));
119 var frame = mapStackTrace(mapping, trace, sdkRoot: "sdk/").frames.first;
120 expect(frame.uri, equals(Uri.parse("dart:async/foo.dart")));
121 expect(frame.line, equals(2));
122 expect(frame.column, equals(4));
123 });
124
125 group("cleans up", () {
126 test("Firefox junk", () {
127 expect(_prettify("foo/<"), equals("foo"));
128 expect(_prettify("foo<"), equals("foo"));
129 });
130
131 test("arity indicators", () {
132 expect(_prettify(r"foo$1"), equals("foo"));
133 expect(_prettify(r"foo$1234"), equals("foo"));
134 });
135
136 test("closures", () {
137 expect(_prettify("foo_closure.call"), equals("foo.<fn>"));
138 });
139
140 test("nested closures", () {
141 expect(_prettify("foo__closure.call"), equals("foo.<fn>.<fn>"));
142 expect(_prettify("foo____closure.call"),
143 equals("foo.<fn>.<fn>.<fn>.<fn>"));
144 });
145
146 test(".call", () {
147 expect(_prettify("foo.call"), equals("foo"));
148 });
149
150 test("top-level functions", () {
151 expect(_prettify("dart.foo"), equals("foo"));
152 });
153
154 test("library namespaces", () {
155 expect(_prettify(r"my_library$foo"), equals("foo"));
156 });
157
158 test("static methods", () {
159 expect(_prettify(r"Foo.static.foo"), equals("foo"));
160 });
161
162 test("instance methods", () {
163 expect(_prettify(r"Foo_bar__baz"), equals("Foo.bar._baz"));
164 });
165
166 test("lots of stuff", () {
167 expect(_prettify(r"lib$Foo.static.lib$Foo_closure.call$0/<"),
168 equals("Foo.<fn>"));
169 });
170 });
171 }
172
173 /// Runs the mapper's prettification logic on [member] and returns the result.
174 String _prettify(String member) {
175 var trace = new Trace([new Frame(Uri.parse("foo.dart.js"), 10, 11, member)]);
176 return mapStackTrace(_simpleMapping, trace).frames.first.member;
177 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | todo.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698