OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
6 import 'package:source_span/source_span.dart'; | 6 import 'package:source_span/source_span.dart'; |
7 import 'package:source_span/src/colors.dart' as colors; | 7 import 'package:source_span/src/colors.dart' as colors; |
8 | 8 |
9 main() { | 9 main() { |
10 var span; | 10 var span; |
(...skipping 18 matching lines...) Expand all Loading... |
29 expect(() => new SourceSpan(start, end, "_"), throwsArgumentError); | 29 expect(() => new SourceSpan(start, end, "_"), throwsArgumentError); |
30 }); | 30 }); |
31 | 31 |
32 test('text must be the right length', () { | 32 test('text must be the right length', () { |
33 var start = new SourceLocation(0); | 33 var start = new SourceLocation(0); |
34 var end = new SourceLocation(1); | 34 var end = new SourceLocation(1); |
35 expect(() => new SourceSpan(start, end, "abc"), throwsArgumentError); | 35 expect(() => new SourceSpan(start, end, "abc"), throwsArgumentError); |
36 }); | 36 }); |
37 }); | 37 }); |
38 | 38 |
| 39 group('for new SourceSpanWithContext()', () { |
| 40 test('contextLine must contain text', () { |
| 41 var start = new SourceLocation(2); |
| 42 var end = new SourceLocation(5); |
| 43 expect(() => new SourceSpanWithContext( |
| 44 start, end, "abc", "--axc--"), throwsArgumentError); |
| 45 }); |
| 46 |
| 47 test('text starts at start.column in contentLine', () { |
| 48 var start = new SourceLocation(3); |
| 49 var end = new SourceLocation(5); |
| 50 expect(() => new SourceSpanWithContext( |
| 51 start, end, "abc", "--abc--"), throwsArgumentError); |
| 52 }); |
| 53 }); |
| 54 |
39 group('for union()', () { | 55 group('for union()', () { |
40 test('source URLs must match', () { | 56 test('source URLs must match', () { |
41 var other = new SourceSpan( | 57 var other = new SourceSpan( |
42 new SourceLocation(12, sourceUrl: "bar.dart"), | 58 new SourceLocation(12, sourceUrl: "bar.dart"), |
43 new SourceLocation(13, sourceUrl: "bar.dart"), | 59 new SourceLocation(13, sourceUrl: "bar.dart"), |
44 "_"); | 60 "_"); |
45 | 61 |
46 expect(() => span.union(other), throwsArgumentError); | 62 expect(() => span.union(other), throwsArgumentError); |
47 }); | 63 }); |
48 | 64 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 expect(span.message("oh no", color: false), equals(""" | 187 expect(span.message("oh no", color: false), equals(""" |
172 line 1, column 6 of foo.dart: oh no | 188 line 1, column 6 of foo.dart: oh no |
173 foo bar | 189 foo bar |
174 ^^^^^^^""")); | 190 ^^^^^^^""")); |
175 }); | 191 }); |
176 | 192 |
177 test("colorizes if color is true", () { | 193 test("colorizes if color is true", () { |
178 expect(span.message("oh no", color: true), | 194 expect(span.message("oh no", color: true), |
179 equals(""" | 195 equals(""" |
180 line 1, column 6 of foo.dart: oh no | 196 line 1, column 6 of foo.dart: oh no |
181 ${colors.RED}foo bar | 197 ${colors.RED}foo bar${colors.NONE} |
182 ^^^^^^^${colors.NONE}""")); | 198 ${colors.RED}^^^^^^^${colors.NONE}""")); |
183 }); | 199 }); |
184 | 200 |
185 test("uses the given color if it's passed", () { | 201 test("uses the given color if it's passed", () { |
186 expect(span.message("oh no", color: colors.YELLOW), equals(""" | 202 expect(span.message("oh no", color: colors.YELLOW), equals(""" |
187 line 1, column 6 of foo.dart: oh no | 203 line 1, column 6 of foo.dart: oh no |
188 ${colors.YELLOW}foo bar | 204 ${colors.YELLOW}foo bar${colors.NONE} |
189 ^^^^^^^${colors.NONE}""")); | 205 ${colors.YELLOW}^^^^^^^${colors.NONE}""")); |
190 }); | 206 }); |
191 }); | 207 }); |
192 | 208 |
| 209 group("message() with context", () { |
| 210 var spanWithContext; |
| 211 setUp(() { |
| 212 spanWithContext = new SourceSpanWithContext( |
| 213 new SourceLocation(5, sourceUrl: "foo.dart"), |
| 214 new SourceLocation(12, sourceUrl: "foo.dart"), |
| 215 "foo bar", |
| 216 "-----foo bar-----"); |
| 217 }); |
| 218 |
| 219 test("underlines under the right column", () { |
| 220 expect(spanWithContext.message("oh no", color: colors.YELLOW), equals(""" |
| 221 line 1, column 6 of foo.dart: oh no |
| 222 -----${colors.YELLOW}foo bar${colors.NONE}----- |
| 223 ${colors.YELLOW}^^^^^^^${colors.NONE}""")); |
| 224 }); |
| 225 }); |
| 226 |
193 group("compareTo()", () { | 227 group("compareTo()", () { |
194 test("sorts by start location first", () { | 228 test("sorts by start location first", () { |
195 var other = new SourceSpan( | 229 var other = new SourceSpan( |
196 new SourceLocation(6, sourceUrl: "foo.dart"), | 230 new SourceLocation(6, sourceUrl: "foo.dart"), |
197 new SourceLocation(14, sourceUrl: "foo.dart"), | 231 new SourceLocation(14, sourceUrl: "foo.dart"), |
198 "oo bar b"); | 232 "oo bar b"); |
199 | 233 |
200 expect(span.compareTo(other), lessThan(0)); | 234 expect(span.compareTo(other), lessThan(0)); |
201 expect(other.compareTo(span), greaterThan(0)); | 235 expect(other.compareTo(span), greaterThan(0)); |
202 }); | 236 }); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 test("a different source URL isn't equal", () { | 281 test("a different source URL isn't equal", () { |
248 var other = new SourceSpan( | 282 var other = new SourceSpan( |
249 new SourceLocation(5, sourceUrl: "bar.dart"), | 283 new SourceLocation(5, sourceUrl: "bar.dart"), |
250 new SourceLocation(12, sourceUrl: "bar.dart"), | 284 new SourceLocation(12, sourceUrl: "bar.dart"), |
251 "foo bar"); | 285 "foo bar"); |
252 | 286 |
253 expect(span, isNot(equals(other))); | 287 expect(span, isNot(equals(other))); |
254 }); | 288 }); |
255 }); | 289 }); |
256 } | 290 } |
OLD | NEW |