|
5 | 5 |
|
6 | 6 | import { expect } from 'chai';
|
7 | 7 | 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'; |
9 | 9 |
|
10 | 10 | suite('parseRange()', () => {
|
11 | 11 | test('valid strings', async () => {
|
@@ -98,3 +98,52 @@ suite('parsePosition()', () => {
|
98 | 98 | }
|
99 | 99 | });
|
100 | 100 | });
|
| 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