@@ -10,181 +10,87 @@ interface StyledOffsets {
10
10
offsets : CharacterOffsets ;
11
11
}
12
12
13
+ /**
14
+ * Compact representation of an input to `handleMultipleLines`. The first
15
+ * element is the character offsets of the first line, and the rest are the
16
+ * character offsets of the end of the remaining lines. We use a single number
17
+ * for lines after the first because they always start at character 0.
18
+ */
19
+ type Input = [ CharacterOffsets , ...number [ ] ] ;
20
+
21
+ /**
22
+ * Compact representation of the expected highlights for a single line. The
23
+ * first element is the line number, the second is the character offsets, and
24
+ * the third is the border styles for the top, bottom, left, and right borders
25
+ * respectively.
26
+ */
27
+ type LineDecorations = [
28
+ number ,
29
+ CharacterOffsets ,
30
+ [ BorderStyle , BorderStyle , BorderStyle , BorderStyle ] ,
31
+ ] ;
32
+
13
33
interface TestCase {
14
- input : CharacterOffsets [ ] ;
15
- expected : StyledOffsets [ ] [ ] ;
34
+ input : Input ;
35
+ expected : LineDecorations [ ] ;
16
36
}
17
37
38
+ const solid = BorderStyle . solid ;
39
+ const porous = BorderStyle . porous ;
40
+ const none = BorderStyle . none ;
41
+
18
42
const testCases : TestCase [ ] = [
19
43
{
20
- input : [
21
- [ 0 , 1 ] ,
22
- [ 0 , 1 ] ,
23
- ] ,
44
+ input : [ [ 0 , 1 ] , 1 ] ,
24
45
expected : [
25
- [
26
- {
27
- offsets : [ 0 , 1 ] ,
28
- style : {
29
- left : BorderStyle . solid ,
30
- right : BorderStyle . porous ,
31
- top : BorderStyle . solid ,
32
- bottom : BorderStyle . none ,
33
- } ,
34
- } ,
35
- ] ,
36
- [
37
- {
38
- offsets : [ 0 , 1 ] ,
39
- style : {
40
- left : BorderStyle . porous ,
41
- right : BorderStyle . solid ,
42
- top : BorderStyle . none ,
43
- bottom : BorderStyle . solid ,
44
- } ,
45
- } ,
46
- ] ,
46
+ [ 0 , [ 0 , 1 ] , [ solid , porous , none , solid ] ] ,
47
+ [ 1 , [ 0 , 1 ] , [ none , solid , solid , porous ] ] ,
47
48
] ,
48
49
} ,
49
50
{
50
- input : [
51
- [ 1 , 2 ] ,
52
- [ 0 , 1 ] ,
53
- ] ,
51
+ input : [ [ 1 , 2 ] , 1 ] ,
54
52
expected : [
55
- [
56
- {
57
- offsets : [ 1 , 2 ] ,
58
- style : {
59
- left : BorderStyle . solid ,
60
- right : BorderStyle . porous ,
61
- top : BorderStyle . solid ,
62
- bottom : BorderStyle . solid ,
63
- } ,
64
- } ,
65
- ] ,
66
- [
67
- {
68
- offsets : [ 0 , 1 ] ,
69
- style : {
70
- left : BorderStyle . porous ,
71
- right : BorderStyle . solid ,
72
- top : BorderStyle . solid ,
73
- bottom : BorderStyle . solid ,
74
- } ,
75
- } ,
76
- ] ,
53
+ [ 0 , [ 1 , 2 ] , [ solid , porous , solid , solid ] ] ,
54
+ [ 1 , [ 0 , 1 ] , [ solid , solid , solid , porous ] ] ,
77
55
] ,
78
56
} ,
79
57
{
80
- input : [
81
- [ 1 , 3 ] ,
82
- [ 0 , 2 ] ,
83
- ] ,
58
+ input : [ [ 1 , 3 ] , 2 ] ,
84
59
expected : [
85
- [
86
- {
87
- offsets : [ 1 , 2 ] ,
88
- style : {
89
- left : BorderStyle . solid ,
90
- right : BorderStyle . none ,
91
- top : BorderStyle . solid ,
92
- bottom : BorderStyle . none ,
93
- } ,
94
- } ,
95
- {
96
- offsets : [ 2 , 3 ] ,
97
- style : {
98
- left : BorderStyle . none ,
99
- right : BorderStyle . porous ,
100
- top : BorderStyle . solid ,
101
- bottom : BorderStyle . solid ,
102
- } ,
103
- } ,
104
- ] ,
105
- [
106
- {
107
- offsets : [ 0 , 1 ] ,
108
- style : {
109
- left : BorderStyle . porous ,
110
- right : BorderStyle . none ,
111
- top : BorderStyle . solid ,
112
- bottom : BorderStyle . solid ,
113
- } ,
114
- } ,
115
- {
116
- offsets : [ 1 , 2 ] ,
117
- style : {
118
- left : BorderStyle . none ,
119
- right : BorderStyle . solid ,
120
- top : BorderStyle . none ,
121
- bottom : BorderStyle . solid ,
122
- } ,
123
- } ,
124
- ] ,
60
+ [ 0 , [ 1 , 2 ] , [ solid , none , none , solid ] ] ,
61
+ [ 0 , [ 2 , 3 ] , [ solid , porous , solid , none ] ] ,
62
+ [ 1 , [ 0 , 1 ] , [ solid , none , solid , porous ] ] ,
63
+ [ 1 , [ 1 , 2 ] , [ none , solid , solid , none ] ] ,
125
64
] ,
126
65
} ,
127
66
{
128
- input : [
129
- [ 0 , 0 ] ,
130
- [ 0 , 0 ] ,
131
- [ 0 , 0 ] ,
132
- ] ,
67
+ input : [ [ 0 , 0 ] , 0 , 0 ] ,
133
68
expected : [
134
- [
135
- {
136
- offsets : [ 0 , 0 ] ,
137
- style : {
138
- left : BorderStyle . solid ,
139
- right : BorderStyle . porous ,
140
- top : BorderStyle . solid ,
141
- bottom : BorderStyle . none ,
142
- } ,
143
- } ,
144
- ] ,
145
- [
146
- {
147
- offsets : [ 0 , 0 ] ,
148
- style : {
149
- left : BorderStyle . porous ,
150
- right : BorderStyle . porous ,
151
- top : BorderStyle . porous ,
152
- bottom : BorderStyle . none ,
153
- } ,
154
- } ,
155
- ] ,
156
- [
157
- {
158
- offsets : [ 0 , 0 ] ,
159
- style : {
160
- left : BorderStyle . porous ,
161
- right : BorderStyle . solid ,
162
- top : BorderStyle . porous ,
163
- bottom : BorderStyle . solid ,
164
- } ,
165
- } ,
166
- ] ,
69
+ [ 0 , [ 0 , 0 ] , [ solid , porous , none , solid ] ] ,
70
+ [ 1 , [ 0 , 0 ] , [ porous , porous , none , porous ] ] ,
71
+ [ 2 , [ 0 , 0 ] , [ porous , solid , solid , porous ] ] ,
167
72
] ,
168
73
} ,
169
74
] ;
170
75
171
76
suite ( "handleMultipleLines" , ( ) => {
172
77
for ( const testCase of testCases ) {
173
78
test ( JSON . stringify ( testCase . input ) , ( ) => {
79
+ const [ firstLine , ...rest ] = testCase . input ;
80
+
174
81
const actual = [
175
- ...handleMultipleLines (
176
- testCase . input . map (
177
- ( [ start , end ] , index ) => new Range ( index , start , index , end ) ,
178
- ) ,
179
- ) ,
82
+ ...handleMultipleLines ( [
83
+ new Range ( 0 , firstLine [ 0 ] , 0 , firstLine [ 1 ] ) ,
84
+ ...rest . map ( ( end , index ) => new Range ( index + 1 , 0 , index + 1 , end ) ) ,
85
+ ] ) ,
180
86
] ;
181
87
assert . deepStrictEqual (
182
88
actual ,
183
- testCase . expected . flatMap ( ( lineOffsets , index ) =>
184
- lineOffsets . map ( ( { style , offsets : [ start , end ] } ) => ( {
185
- range : new Range ( index , start , index , end ) ,
186
- style,
187
- } ) ) ,
89
+ testCase . expected . map (
90
+ ( [ lineNumber , [ start , end ] , [ top , right , bottom , left ] ] ) => ( {
91
+ range : new Range ( lineNumber , start , lineNumber , end ) ,
92
+ style : { top , right , bottom , left } ,
93
+ } ) ,
188
94
) ,
189
95
) ;
190
96
} ) ;
0 commit comments