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

Side by Side Diff: pkg/source_maps/test/span_test.dart

Issue 18749005: Fixes in sourcemaps discovered in csslib (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« pkg/source_maps/lib/span.dart ('K') | « pkg/source_maps/lib/span.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.span_test; 5 library test.span_test;
6 6
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 import 'package:source_maps/span.dart'; 8 import 'package:source_maps/span.dart';
9 9
10 const String TEST_FILE = ''' 10 const String TEST_FILE = '''
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 expect(col(i), i - lineOffset, reason: 'position: $i'); 62 expect(col(i), i - lineOffset, reason: 'position: $i');
63 } 63 }
64 }); 64 });
65 65
66 test('get text', () { 66 test('get text', () {
67 // fifth line (including 4 new lines), columns 2 .. 11 67 // fifth line (including 4 new lines), columns 2 .. 11
68 var line = 10 + 80 + 31 + 27 + 4; 68 var line = 10 + 80 + 31 + 27 + 4;
69 expect(file.getText(line + 2, line + 11), '34+6789_1'); 69 expect(file.getText(line + 2, line + 11), '34+6789_1');
70 }); 70 });
71 71
72 test('get location message', () { 72 group('location message', () {
73 // fifth line (including 4 new lines), columns 2 .. 11 73 test('first line', () {
74 var line = 10 + 80 + 31 + 27 + 4; 74 expect(file.getLocationMessage('the message', 1, 3),
75 expect(file.getLocationMessage('the message', line + 2, line + 11), 75 'file:1:2: the message\n'
76 'file:5:3: the message\n' 76 '+23456789_\n'
77 '1234+6789_1234\n' 77 ' ^^');
78 ' ^^^^^^^^^'); 78 });
79 });
80 79
81 test('get location message - no file url', () { 80 test('in the middle of the file', () {
82 var line = 10 + 80 + 31 + 27 + 4; 81 // fifth line (including 4 new lines), columns 2 .. 11
83 expect(new SourceFile.text(null, TEST_FILE).getLocationMessage( 82 var line = 10 + 80 + 31 + 27 + 4;
84 'the message', line + 2, line + 11), 83 expect(file.getLocationMessage('the message', line + 2, line + 11),
85 ':5:3: the message\n' 84 'file:5:3: the message\n'
86 '1234+6789_1234\n' 85 '1234+6789_1234\n'
87 ' ^^^^^^^^^'); 86 ' ^^^^^^^^^');
87 });
88
89 test('no file url', () {
90 var line = 10 + 80 + 31 + 27 + 4;
91 expect(new SourceFile.text(null, TEST_FILE).getLocationMessage(
92 'the message', line + 2, line + 11),
93 ':5:3: the message\n'
94 '1234+6789_1234\n'
95 ' ^^^^^^^^^');
96 });
97
98 test('penultimate line', () {
99 // We search '\n' backwards twice because last line is \n terminated:
100 int index = TEST_FILE.lastIndexOf('\n');
101 var start = TEST_FILE.lastIndexOf('\n', index - 1) - 3;
102 expect(file.getLocationMessage('the message', start, start + 2),
103 'file:11:41: the message\n'
104 '123456789_+23456789_123456789_123456789_123\n'
105 ' ^^');
106 });
107
108 test('last line', () {
109 var start = TEST_FILE.lastIndexOf('\n') - 2;
110 expect(file.getLocationMessage('the message', start, start + 1),
111 'file:12:28: the message\n'
112 '123456789_1+3456789_123456789\n'
113 ' ^');
114 });
115
116 group('no trailing empty-line at the end -', () {
117 var text = TEST_FILE.substring(0, TEST_FILE.length - 1);
118 var file2 = new SourceFile.text('file', text);
119
120 test('penultimate line', () {
121 var start = text.lastIndexOf('\n') - 3;
122 expect(file2.getLocationMessage('the message', start, start + 2),
123 'file:11:41: the message\n'
124 '123456789_+23456789_123456789_123456789_123\n'
125 ' ^^');
126 });
127
128 test('last line', () {
129 var start = text.length - 2;
130 expect(file2.getLocationMessage('the message', start, start + 1),
131 'file:12:28: the message\n'
132 '123456789_1+3456789_123456789\n'
133 ' ^');
134 });
135 });
136
137 test('single line', () {
138 var text = "this is a single line";
139 int start = text.indexOf(' ') + 1;
140 var file2 = new SourceFile.text('file', text);
141 expect(file2.getLocationMessage('the message', start, start + 2),
142 'file:1:${start + 1}: the message\n'
143 'this is a single line\n'
144 ' ^^');
145 });
88 }); 146 });
89 147
90 test('location getters', () { 148 test('location getters', () {
91 expect(loc(8).line, 0); 149 expect(loc(8).line, 0);
92 expect(loc(8).column, 8); 150 expect(loc(8).column, 8);
93 expect(loc(9).line, 0); 151 expect(loc(9).line, 0);
94 expect(loc(9).column, 9); 152 expect(loc(9).column, 9);
95 expect(loc(8).formatString, 'file:1:9'); 153 expect(loc(8).formatString, 'file:1:9');
96 expect(loc(12).line, 1); 154 expect(loc(12).line, 1);
97 expect(loc(12).column, 1); 155 expect(loc(12).column, 1);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 file.getLocationMessage('the message', start, start + 2)); 293 file.getLocationMessage('the message', start, start + 2));
236 }); 294 });
237 295
238 test('past segment, past its line', () { 296 test('past segment, past its line', () {
239 var start = TEST_FILE.length - 2; 297 var start = TEST_FILE.length - 2;
240 expect(file.getLocationMessage('the message', start, start + 1), 298 expect(file.getLocationMessage('the message', start, start + 1),
241 'file:12:29: the message\n' 299 'file:12:29: the message\n'
242 '123456789_1+3456789_123456789\n' 300 '123456789_1+3456789_123456789\n'
243 ' ^'); 301 ' ^');
244 302
245 // TODO(sigmund): consider also fixing this and report file:10:4
246 // The answer below is different because the segment parsing only knows 303 // The answer below is different because the segment parsing only knows
247 // about the 10 lines it has (and nothing about the possible extra lines 304 // about the 10 lines it has (and nothing about the possible extra lines
248 // afterwards) 305 // afterwards)
249 expect(segment.getLocationMessage('the message', start, start + 1), 306 expect(segment.getLocationMessage('the message', start, start + 1),
250 'file:10:112: the message\n'); 307 'file:11:1: the message\n');
251
252 // The number 112 includes the count of extra characters past the
253 // segment, which we verify here:
254 var lastSegmentLineStart = segmentText.lastIndexOf('\n');
255 expect(start - baseOffset - lastSegmentLineStart, 112);
256 }); 308 });
257 }); 309 });
258 }); 310 });
259 311
260 test('span isIdentifier defaults to false', () { 312 test('span isIdentifier defaults to false', () {
261 var start = new TestLocation(0); 313 var start = new TestLocation(0);
262 var end = new TestLocation(1); 314 var end = new TestLocation(1);
263 expect(new TestSpan(start, end).isIdentifier, false); 315 expect(new TestSpan(start, end).isIdentifier, false);
264 expect(file.span(8, 9, null).isIdentifier, false); 316 expect(file.span(8, 9, null).isIdentifier, false);
265 expect(new FixedSpan('', 8, 1, 8, isIdentifier: null).isIdentifier, false); 317 expect(new FixedSpan('', 8, 1, 8, isIdentifier: null).isIdentifier, false);
266 }); 318 });
267 } 319 }
268 320
269 class TestSpan extends Span { 321 class TestSpan extends Span {
270 TestSpan(Location start, Location end) : super(start, end, null); 322 TestSpan(Location start, Location end) : super(start, end, null);
271 get text => null; 323 get text => null;
272 } 324 }
273 325
274 class TestLocation extends Location { 326 class TestLocation extends Location {
275 String get sourceUrl => ''; 327 String get sourceUrl => '';
276 TestLocation(int offset) : super(offset); 328 TestLocation(int offset) : super(offset);
277 get line => 0; 329 get line => 0;
278 get column => 0; 330 get column => 0;
279 } 331 }
OLDNEW
« pkg/source_maps/lib/span.dart ('K') | « pkg/source_maps/lib/span.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698