Skip to content

Commit ed42ca8

Browse files
committed
Add coverage to some text utils functions
1 parent 6054c98 commit ed42ca8

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/test/common/utils/text.unit.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { expect } from 'chai';
77
import { Position, Range } from 'vscode';
8-
import { parsePosition, parseRange } from '../../../client/common/utils/text';
8+
import { getDedentedLines, getIndent, parsePosition, parseRange } from '../../../client/common/utils/text';
99

1010
suite('parseRange()', () => {
1111
test('valid strings', async () => {
@@ -98,3 +98,52 @@ suite('parsePosition()', () => {
9898
}
9999
});
100100
});
101+
102+
suite('getIndent()', () => {
103+
const testsData = [
104+
{ line: 'text', expected: '' },
105+
{ line: ' text', expected: ' ' },
106+
{ line: ' text', expected: ' ' },
107+
{ line: ' tabulatedtext', expected: '' },
108+
];
109+
110+
testsData.forEach((testData) => {
111+
test(`getIndent when line is ${testData.line}`, () => {
112+
const indent = getIndent(testData.line);
113+
114+
expect(indent).equal(testData.expected);
115+
});
116+
});
117+
});
118+
119+
suite('getDedentedLines()', () => {
120+
const testsData = [
121+
{ text: '', expected: [] },
122+
{ text: '\n', expected: Error, exceptionMessage: 'expected "first" line to not be blank' },
123+
{ text: 'line1\n', expected: Error, exceptionMessage: 'expected actual first line to be blank' },
124+
{
125+
text: '\n line2\n line3',
126+
expected: Error,
127+
exceptionMessage: 'line 1 has less indent than the "first" line',
128+
},
129+
{
130+
text: '\n line2\n line3',
131+
expected: ['line2', 'line3'],
132+
},
133+
{
134+
text: '\n line2\n line3',
135+
expected: ['line2', ' line3'],
136+
},
137+
];
138+
139+
testsData.forEach((testData) => {
140+
test(`getDedentedLines when line is ${testData.text}`, () => {
141+
if (Array.isArray(testData.expected)) {
142+
const dedentedLines = getDedentedLines(testData.text);
143+
expect(dedentedLines).to.deep.equal(testData.expected);
144+
} else {
145+
expect(() => getDedentedLines(testData.text)).to.throw(testData.expected, testData.exceptionMessage);
146+
}
147+
});
148+
});
149+
});

0 commit comments

Comments
 (0)