OLD | NEW |
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 = ''' |
11 +23456789_ | 11 +23456789_ |
12 + _123456789_123456789_123456789_123456789_123456789_123456789_123456789_ | 12 + _123456789_123456789_123456789_123456789_123456789_123456789_123456789_ |
13 + _123456789_1 | 13 + _123456789_1 |
14 123+56789_123456789_1234567 | 14 123+56789_123456789_1234567 |
15 1234+6789_1234 | 15 1234+6789_1234 |
16 12345+789_123456789_12345 | 16 12345+789_123456789_12345 |
17 123456+89_123456789_123456789_123456789_123456789_123456789_123456789_123456789 | 17 123456+89_123456789_123456789_123456789_123456789_123456789_123456789_123456789 |
18 1234567+9_123456789_123456789_123456789_123456789_123456789_123456789_123 | 18 1234567+9_123456789_123456789_123456789_123456789_123456789_123456789_123 |
19 12345678+_123456789_123456789_123456789_123456789_1 | 19 12345678+_123456789_123456789_123456789_123456789_1 |
20 123456789+123456789_123456789_12345678 | 20 123456789+123456789_123456789_12345678 |
21 123456789_+23456789_123456789_123456789_123 | 21 123456789_+23456789_123456789_123456789_123 |
22 123456789_1+3456789_123456789 | 22 123456789_1+3456789_123456789 |
23 '''; | 23 '''; |
24 | 24 |
25 List<int> newLines = TEST_FILE.split('\n').map((s) => s.length).toList(); | 25 List<int> newLines = TEST_FILE.split('\n').map((s) => s.length).toList(); |
26 | 26 |
27 main() { | 27 main() { |
28 var file = new File.text('file', TEST_FILE); | 28 var file = new SourceFile.text('file', TEST_FILE); |
29 span(int start, int end) => file.span(start, end); | 29 span(int start, int end) => file.span(start, end); |
30 loc(int offset) => file.location(offset); | 30 loc(int offset) => file.location(offset); |
31 | 31 |
32 test('validate test input', () { | 32 test('validate test input', () { |
33 expect(newLines, | 33 expect(newLines, |
34 const [10, 80, 31, 27, 14, 25, 79, 73, 51, 38, 43, 29, 0]); | 34 const [10, 80, 31, 27, 14, 25, 79, 73, 51, 38, 43, 29, 0]); |
35 }); | 35 }); |
36 | 36 |
37 test('get line and column', () { | 37 test('get line and column', () { |
38 line(int n) => file.getLine(n); | 38 line(int n) => file.getLine(n); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // fifth line (including 4 new lines), columns 2 .. 11 | 73 // fifth line (including 4 new lines), columns 2 .. 11 |
74 var line = 10 + 80 + 31 + 27 + 4; | 74 var line = 10 + 80 + 31 + 27 + 4; |
75 expect(file.getLocationMessage('the message', line + 2, line + 11), | 75 expect(file.getLocationMessage('the message', line + 2, line + 11), |
76 'file:5:3: the message\n' | 76 'file:5:3: the message\n' |
77 '1234+6789_1234\n' | 77 '1234+6789_1234\n' |
78 ' ^^^^^^^^^'); | 78 ' ^^^^^^^^^'); |
79 }); | 79 }); |
80 | 80 |
81 test('get location message - no file url', () { | 81 test('get location message - no file url', () { |
82 var line = 10 + 80 + 31 + 27 + 4; | 82 var line = 10 + 80 + 31 + 27 + 4; |
83 expect(new File.text(null, TEST_FILE).getLocationMessage( | 83 expect(new SourceFile.text(null, TEST_FILE).getLocationMessage( |
84 'the message', line + 2, line + 11), | 84 'the message', line + 2, line + 11), |
85 ':5:3: the message\n' | 85 ':5:3: the message\n' |
86 '1234+6789_1234\n' | 86 '1234+6789_1234\n' |
87 ' ^^^^^^^^^'); | 87 ' ^^^^^^^^^'); |
88 }); | 88 }); |
89 | 89 |
90 test('location getters', () { | 90 test('location getters', () { |
91 expect(loc(8).line, 0); | 91 expect(loc(8).line, 0); |
92 expect(loc(8).column, 8); | 92 expect(loc(8).column, 8); |
93 expect(loc(9).line, 0); | 93 expect(loc(9).line, 0); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 expect(span.start.offset, greaterThanOrEqualTo(lastStart)); | 159 expect(span.start.offset, greaterThanOrEqualTo(lastStart)); |
160 if (span.start.offset == lastStart) { | 160 if (span.start.offset == lastStart) { |
161 expect(span.end.offset, greaterThanOrEqualTo(lastEnd)); | 161 expect(span.end.offset, greaterThanOrEqualTo(lastEnd)); |
162 } | 162 } |
163 lastStart = span.start.offset; | 163 lastStart = span.start.offset; |
164 lastEnd = span.end.offset; | 164 lastEnd = span.end.offset; |
165 } | 165 } |
166 }); | 166 }); |
167 | 167 |
168 test('file segment', () { | 168 test('file segment', () { |
169 var segment = new FileSegment('file', TEST_FILE.substring(12), loc(12)); | 169 var segment = new SourceFileSegment('file', |
| 170 TEST_FILE.substring(12), loc(12)); |
170 sline(int n) => segment.getLine(n); | 171 sline(int n) => segment.getLine(n); |
171 scol(int n) => segment.getColumn(segment.getLine(n), n); | 172 scol(int n) => segment.getColumn(segment.getLine(n), n); |
172 | 173 |
173 line(int n) => file.getLine(n); | 174 line(int n) => file.getLine(n); |
174 col(int n) => file.getColumn(file.getLine(n), n); | 175 col(int n) => file.getColumn(file.getLine(n), n); |
175 | 176 |
176 int j = 0; | 177 int j = 0; |
177 int lineOffset = 0; | 178 int lineOffset = 0; |
178 for (int i = 12; i < TEST_FILE.length; i++) { | 179 for (int i = 12; i < TEST_FILE.length; i++) { |
179 if (i > lineOffset + newLines[j]) { | 180 if (i > lineOffset + newLines[j]) { |
(...skipping 20 matching lines...) Expand all Loading... |
200 expect(new FixedSpan('', 8, 1, 8, isIdentifier: null).isIdentifier, false); | 201 expect(new FixedSpan('', 8, 1, 8, isIdentifier: null).isIdentifier, false); |
201 }); | 202 }); |
202 } | 203 } |
203 | 204 |
204 class TestSpan extends Span { | 205 class TestSpan extends Span { |
205 TestSpan(Location start, Location end) : super(start, end, null); | 206 TestSpan(Location start, Location end) : super(start, end, null); |
206 get text => null; | 207 get text => null; |
207 } | 208 } |
208 | 209 |
209 class TestLocation extends Location { | 210 class TestLocation extends Location { |
| 211 String get sourceUrl => ''; |
210 TestLocation(int offset) : super(offset); | 212 TestLocation(int offset) : super(offset); |
211 get line => 0; | 213 get line => 0; |
212 get column => 0; | 214 get column => 0; |
213 } | 215 } |
OLD | NEW |