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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 start, end, "abc", "\n--abc--"), throwsArgumentError); | 58 start, end, "abc", "\n--abc--"), throwsArgumentError); |
59 expect(() => new SourceSpanWithContext( | 59 expect(() => new SourceSpanWithContext( |
60 start, end, "abc", "\n----abc--"), throwsArgumentError); | 60 start, end, "abc", "\n----abc--"), throwsArgumentError); |
61 expect(() => new SourceSpanWithContext( | 61 expect(() => new SourceSpanWithContext( |
62 start, end, "abc", "\n\n--abc--"), throwsArgumentError); | 62 start, end, "abc", "\n\n--abc--"), throwsArgumentError); |
63 | 63 |
64 // However, these are valid: | 64 // However, these are valid: |
65 new SourceSpanWithContext(start, end, "abc", "\n---abc--"); | 65 new SourceSpanWithContext(start, end, "abc", "\n---abc--"); |
66 new SourceSpanWithContext(start, end, "abc", "\n\n---abc--"); | 66 new SourceSpanWithContext(start, end, "abc", "\n\n---abc--"); |
67 }); | 67 }); |
| 68 |
| 69 test('text can occur multiple times in context', () { |
| 70 var start1 = new SourceLocation(4, line: 55, column: 2); |
| 71 var end1 = new SourceLocation(7, line: 55, column: 5); |
| 72 var start2 = new SourceLocation(4, line: 55, column: 8); |
| 73 var end2 = new SourceLocation(7, line: 55, column: 11); |
| 74 new SourceSpanWithContext(start1, end1, "abc", "--abc---abc--\n"); |
| 75 new SourceSpanWithContext(start1, end1, "abc", "--abc--abc--\n"); |
| 76 new SourceSpanWithContext(start2, end2, "abc", "--abc---abc--\n"); |
| 77 new SourceSpanWithContext(start2, end2, "abc", "---abc--abc--\n"); |
| 78 expect(() => new SourceSpanWithContext( |
| 79 start1, end1, "abc", "---abc--abc--\n"), throwsArgumentError); |
| 80 expect(() => new SourceSpanWithContext( |
| 81 start2, end2, "abc", "--abc--abc--\n"), throwsArgumentError); |
| 82 }); |
68 }); | 83 }); |
69 | 84 |
70 group('for union()', () { | 85 group('for union()', () { |
71 test('source URLs must match', () { | 86 test('source URLs must match', () { |
72 var other = new SourceSpan( | 87 var other = new SourceSpan( |
73 new SourceLocation(12, sourceUrl: "bar.dart"), | 88 new SourceLocation(12, sourceUrl: "bar.dart"), |
74 new SourceLocation(13, sourceUrl: "bar.dart"), | 89 new SourceLocation(13, sourceUrl: "bar.dart"), |
75 "_"); | 90 "_"); |
76 | 91 |
77 expect(() => span.union(other), throwsArgumentError); | 92 expect(() => span.union(other), throwsArgumentError); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 "-----foo bar-----"); | 246 "-----foo bar-----"); |
232 }); | 247 }); |
233 | 248 |
234 test("underlines under the right column", () { | 249 test("underlines under the right column", () { |
235 expect(spanWithContext.message("oh no", color: colors.YELLOW), equals(""" | 250 expect(spanWithContext.message("oh no", color: colors.YELLOW), equals(""" |
236 line 1, column 6 of foo.dart: oh no | 251 line 1, column 6 of foo.dart: oh no |
237 -----${colors.YELLOW}foo bar${colors.NONE}----- | 252 -----${colors.YELLOW}foo bar${colors.NONE}----- |
238 ${colors.YELLOW}^^^^^^^${colors.NONE}""")); | 253 ${colors.YELLOW}^^^^^^^${colors.NONE}""")); |
239 }); | 254 }); |
240 | 255 |
| 256 test("underlines correctly when text appears twice", () { |
| 257 var span = new SourceSpanWithContext( |
| 258 new SourceLocation(9, column: 9, sourceUrl: "foo.dart"), |
| 259 new SourceLocation(12, column: 12, sourceUrl: "foo.dart"), |
| 260 "foo", |
| 261 "-----foo foo-----"); |
| 262 expect(span.message("oh no", color: colors.YELLOW), equals(""" |
| 263 line 1, column 10 of foo.dart: oh no |
| 264 -----foo ${colors.YELLOW}foo${colors.NONE}----- |
| 265 ${colors.YELLOW}^^^${colors.NONE}""")); |
| 266 }); |
| 267 |
241 test("supports lines of preceeding context", () { | 268 test("supports lines of preceeding context", () { |
242 var span = new SourceSpanWithContext( | 269 var span = new SourceSpanWithContext( |
243 new SourceLocation(5, line: 3, column: 5, sourceUrl: "foo.dart"), | 270 new SourceLocation(5, line: 3, column: 5, sourceUrl: "foo.dart"), |
244 new SourceLocation(12, line: 3, column: 12, sourceUrl: "foo.dart"), | 271 new SourceLocation(12, line: 3, column: 12, sourceUrl: "foo.dart"), |
245 "foo bar", | 272 "foo bar", |
246 "previous\nlines\n-----foo bar-----\nfollowing line\n"); | 273 "previous\nlines\n-----foo bar-----\nfollowing line\n"); |
247 | 274 |
248 expect(span.message("oh no", color: colors.YELLOW), equals(""" | 275 expect(span.message("oh no", color: colors.YELLOW), equals(""" |
249 line 4, column 6 of foo.dart: oh no | 276 line 4, column 6 of foo.dart: oh no |
250 previous | 277 previous |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 test("a different source URL isn't equal", () { | 338 test("a different source URL isn't equal", () { |
312 var other = new SourceSpan( | 339 var other = new SourceSpan( |
313 new SourceLocation(5, sourceUrl: "bar.dart"), | 340 new SourceLocation(5, sourceUrl: "bar.dart"), |
314 new SourceLocation(12, sourceUrl: "bar.dart"), | 341 new SourceLocation(12, sourceUrl: "bar.dart"), |
315 "foo bar"); | 342 "foo bar"); |
316 | 343 |
317 expect(span, isNot(equals(other))); | 344 expect(span, isNot(equals(other))); |
318 }); | 345 }); |
319 }); | 346 }); |
320 } | 347 } |
OLD | NEW |