@@ -13,95 +13,97 @@ main() {
1313foo bar baz
1414whiz bang boom
1515zip zap zop
16- """ , url : "foo.dart" );
16+ """ );
1717 });
1818
1919 test ("points to the span in the source" , () {
20- expect (file.span (4 , 7 ).message ("oh no" ), equals ("""
21- line 1, column 5 of foo.dart: oh no
20+ expect (file.span (4 , 7 ).highlight (), equals ("""
2221foo bar baz
2322 ^^^""" ));
2423 });
2524
2625 test ("gracefully handles a missing source URL" , () {
2726 var span = new SourceFile ("foo bar baz" ).span (4 , 7 );
28- expect (span.message ("oh no" ), equals ("""
29- line 1, column 5: oh no
27+ expect (span.highlight (), equals ("""
3028foo bar baz
3129 ^^^""" ));
3230 });
3331
3432 test ("highlights the first line of a multiline span" , () {
35- expect (file.span (4 , 20 ).message ("oh no" ), equals ("""
36- line 1, column 5 of foo.dart: oh no
33+ expect (file.span (4 , 20 ).highlight (), equals ("""
3734foo bar baz
3835 ^^^^^^^^""" ));
3936 });
4037
4138 test ("works for a point span" , () {
42- expect (file.location (4 ).pointSpan ().message ("oh no" ), equals ("""
43- line 1, column 5 of foo.dart: oh no
39+ expect (file.location (4 ).pointSpan ().highlight (), equals ("""
4440foo bar baz
4541 ^""" ));
4642 });
4743
4844 test ("works for a point span at the end of a line" , () {
49- expect (file.location (11 ).pointSpan ().message ("oh no" ), equals ("""
50- line 1, column 12 of foo.dart: oh no
45+ expect (file.location (11 ).pointSpan ().highlight (), equals ("""
5146foo bar baz
5247 ^""" ));
5348 });
5449
5550 test ("works for a point span at the end of the file" , () {
56- expect (file.location (38 ).pointSpan ().message ("oh no" ), equals ("""
57- line 3, column 12 of foo.dart: oh no
51+ expect (file.location (38 ).pointSpan ().highlight (), equals ("""
5852zip zap zop
5953 ^""" ));
6054 });
6155
6256 test ("works for a point span at the end of the file with no trailing newline" ,
6357 () {
6458 file = new SourceFile ("zip zap zop" );
65- expect (file.location (11 ).pointSpan ().message ("oh no" ), equals ("""
66- line 1, column 12: oh no
59+ expect (file.location (11 ).pointSpan ().highlight (), equals ("""
6760zip zap zop
6861 ^""" ));
6962 });
7063
7164 test ("works for a point span in an empty file" , () {
72- expect (new SourceFile ("" ).location (0 ).pointSpan ().message ( "oh no" ),
65+ expect (new SourceFile ("" ).location (0 ).pointSpan ().highlight ( ),
7366 equals ("""
74- line 1, column 1: oh no
7567
7668^""" ));
7769 });
7870
7971 test ("works for a single-line file without a newline" , () {
80- expect (new SourceFile ("foo bar" ).span (0 , 7 ).message ( "oh no" ),
72+ expect (new SourceFile ("foo bar" ).span (0 , 7 ).highlight ( ),
8173 equals ("""
82- line 1, column 1: oh no
8374foo bar
8475^^^^^^^""" ));
8576 });
8677
78+ test ("supports lines of preceding context" , () {
79+ var span = new SourceSpanWithContext (
80+ new SourceLocation (5 , line: 3 , column: 5 , sourceUrl: "foo.dart" ),
81+ new SourceLocation (12 , line: 3 , column: 12 , sourceUrl: "foo.dart" ),
82+ "foo bar" ,
83+ "previous\n lines\n -----foo bar-----\n following line\n " );
84+
85+ expect (span.highlight (color: colors.YELLOW ), equals ("""
86+ previous
87+ lines
88+ -----${colors .YELLOW }foo bar${colors .NONE }-----
89+ ${colors .YELLOW }^^^^^^^${colors .NONE }""" ));
90+ });
91+
8792 group ("colors" , () {
8893 test ("doesn't colorize if color is false" , () {
89- expect (file.span (4 , 7 ).message ("oh no" , color: false ), equals ("""
90- line 1, column 5 of foo.dart: oh no
94+ expect (file.span (4 , 7 ).highlight (color: false ), equals ("""
9195foo bar baz
9296 ^^^""" ));
9397 });
9498
9599 test ("colorizes if color is true" , () {
96- expect (file.span (4 , 7 ).message ("oh no" , color: true ), equals ("""
97- line 1, column 5 of foo.dart: oh no
100+ expect (file.span (4 , 7 ).highlight (color: true ), equals ("""
98101foo ${colors .RED }bar${colors .NONE } baz
99102 ${colors .RED }^^^${colors .NONE }""" ));
100103 });
101104
102105 test ("uses the given color if it's passed" , () {
103- expect (file.span (4 , 7 ).message ("oh no" , color: colors.YELLOW ), equals ("""
104- line 1, column 5 of foo.dart: oh no
106+ expect (file.span (4 , 7 ).highlight (color: colors.YELLOW ), equals ("""
105107foo ${colors .YELLOW }bar${colors .NONE } baz
106108 ${colors .YELLOW }^^^${colors .NONE }""" ));
107109 });
0 commit comments