Skip to content

Commit e8bc2bc

Browse files
committed
Compactify handleMultipleLines tests
1 parent 1861f62 commit e8bc2bc

File tree

1 file changed

+52
-146
lines changed
  • packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/generateDecorationsForCharacterRange

1 file changed

+52
-146
lines changed

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/generateDecorationsForCharacterRange/handleMultipleLines.test.ts

Lines changed: 52 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -10,181 +10,87 @@ interface StyledOffsets {
1010
offsets: CharacterOffsets;
1111
}
1212

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+
1333
interface TestCase {
14-
input: CharacterOffsets[];
15-
expected: StyledOffsets[][];
34+
input: Input;
35+
expected: LineDecorations[];
1636
}
1737

38+
const solid = BorderStyle.solid;
39+
const porous = BorderStyle.porous;
40+
const none = BorderStyle.none;
41+
1842
const testCases: TestCase[] = [
1943
{
20-
input: [
21-
[0, 1],
22-
[0, 1],
23-
],
44+
input: [[0, 1], 1],
2445
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]],
4748
],
4849
},
4950
{
50-
input: [
51-
[1, 2],
52-
[0, 1],
53-
],
51+
input: [[1, 2], 1],
5452
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]],
7755
],
7856
},
7957
{
80-
input: [
81-
[1, 3],
82-
[0, 2],
83-
],
58+
input: [[1, 3], 2],
8459
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]],
12564
],
12665
},
12766
{
128-
input: [
129-
[0, 0],
130-
[0, 0],
131-
[0, 0],
132-
],
67+
input: [[0, 0], 0, 0],
13368
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]],
16772
],
16873
},
16974
];
17075

17176
suite("handleMultipleLines", () => {
17277
for (const testCase of testCases) {
17378
test(JSON.stringify(testCase.input), () => {
79+
const [firstLine, ...rest] = testCase.input;
80+
17481
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+
]),
18086
];
18187
assert.deepStrictEqual(
18288
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+
}),
18894
),
18995
);
19096
});

0 commit comments

Comments
 (0)