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

Side by Side Diff: tests/compiler/dart2js/line_column_provider_test.dart

Issue 877753008: Fix shift in source map positions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 5 years, 10 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
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 // Unittest for the [LineColumnCollector].
6
7 import 'package:expect/expect.dart';
8 import 'package:compiler/src/io/code_output.dart';
9 import 'package:compiler/src/io/line_column_provider.dart';
10
11 import 'output_collector.dart';
12
13 main() {
14 test([""], {0: [0, 0], 1: null});
15
16 test([" "], {0: [0, 0], 1: [0, 1], 2: null});
17
18 test(["\n "], {0: [0, 0], 1: [1, 0], 2: [1, 1], 3: null});
19
20 Map positions = {0: [0, 0],
21 1: [0, 1],
22 2: [1, 0],
23 3: [1, 1],
24 4: [2, 0],
25 5: [2, 1],
26 6: null};
27
28 test(["a\nb\nc"], positions);
29
30 test(["a", "\nb\nc"], positions);
31
32 test(["a", "\n", "b\nc"], positions);
33
34 CodeBuffer buffer1 = new CodeBuffer();
35 buffer1.add("a\nb\nc");
36 test([buffer1], positions);
37
38 CodeBuffer buffer2 = new CodeBuffer();
39 buffer2.add("\nb\nc");
40 test(["a", buffer2], positions);
41
42 CodeBuffer buffer3 = new CodeBuffer();
43 buffer3.add("a");
44 test([buffer3, buffer2], positions);
45
46 CodeBuffer buffer4 = new CodeBuffer();
47 buffer4.addBuffer(buffer3);
48 test([buffer4, buffer2], positions);
49 }
50
51 test(List events, Map<int, List<int>> expectedPositions) {
floitsch 2015/02/02 10:28:48 move 'test' before main.
Johnni Winther 2015/02/02 10:49:26 Done.
52 BufferedEventSink sink = new BufferedEventSink();
53 LineColumnProvider lineColumnProvider = new LineColumnCollector();
54 CodeOutput output = new StreamCodeOutput(sink, [lineColumnProvider]);
55 for (var event in events) {
56 if (event is String) {
57 output.add(event);
58 } else if (event is CodeBuffer) {
59 output.addBuffer(event);
60 }
61 }
62 output.close();
63
64 expectedPositions.forEach((int offset, List<int> expectedPosition) {
65 if (expectedPosition == null) {
66 Expect.throws(() => lineColumnProvider.getLine(offset),
67 (e) => true,
68 'Expected out-of-bounds offset: $offset\n'
69 'text:"""${sink.text}"""\n'
70 'lineColumnProvider:$lineColumnProvider');
71 } else {
72 int line = lineColumnProvider.getLine(offset);
73 int column = lineColumnProvider.getColumn(line, offset);
74 Expect.equals(expectedPosition[0], line,
75 'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
76 'text:"""${sink.text}"""\n'
77 'lineColumnProvider:$lineColumnProvider');
78 Expect.equals(expectedPosition[1], column,
79 'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
80 'text:"""${sink.text}"""\n'
81 'lineColumnProvider:$lineColumnProvider');
82 }
83 });
84 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/line_column_provider.dart ('k') | tests/compiler/dart2js/source_map_d2js_validity_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698