@@ -13,95 +13,97 @@ main() {
13
13
foo bar baz
14
14
whiz bang boom
15
15
zip zap zop
16
- """ , url : "foo.dart" );
16
+ """ );
17
17
});
18
18
19
19
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 ("""
22
21
foo bar baz
23
22
^^^""" ));
24
23
});
25
24
26
25
test ("gracefully handles a missing source URL" , () {
27
26
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 ("""
30
28
foo bar baz
31
29
^^^""" ));
32
30
});
33
31
34
32
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 ("""
37
34
foo bar baz
38
35
^^^^^^^^""" ));
39
36
});
40
37
41
38
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 ("""
44
40
foo bar baz
45
41
^""" ));
46
42
});
47
43
48
44
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 ("""
51
46
foo bar baz
52
47
^""" ));
53
48
});
54
49
55
50
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 ("""
58
52
zip zap zop
59
53
^""" ));
60
54
});
61
55
62
56
test ("works for a point span at the end of the file with no trailing newline" ,
63
57
() {
64
58
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 ("""
67
60
zip zap zop
68
61
^""" ));
69
62
});
70
63
71
64
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 ( ),
73
66
equals ("""
74
- line 1, column 1: oh no
75
67
76
68
^""" ));
77
69
});
78
70
79
71
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 ( ),
81
73
equals ("""
82
- line 1, column 1: oh no
83
74
foo bar
84
75
^^^^^^^""" ));
85
76
});
86
77
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
+
87
92
group ("colors" , () {
88
93
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 ("""
91
95
foo bar baz
92
96
^^^""" ));
93
97
});
94
98
95
99
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 ("""
98
101
foo ${colors .RED }bar${colors .NONE } baz
99
102
${colors .RED }^^^${colors .NONE }""" ));
100
103
});
101
104
102
105
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 ("""
105
107
foo ${colors .YELLOW }bar${colors .NONE } baz
106
108
${colors .YELLOW }^^^${colors .NONE }""" ));
107
109
});
0 commit comments