|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import { describe, it } from 'mocha'; |
3 | 3 |
|
4 | | -import { dedentBlockStringLines, printBlockString } from '../blockString'; |
| 4 | +import { |
| 5 | + isPrintableAsBlockString, |
| 6 | + dedentBlockStringLines, |
| 7 | + printBlockString, |
| 8 | +} from '../blockString'; |
5 | 9 |
|
6 | 10 | function joinLines(...args: ReadonlyArray<string>) { |
7 | 11 | return args.join('\n'); |
@@ -135,6 +139,69 @@ describe('dedentBlockStringLines', () => { |
135 | 139 | }); |
136 | 140 | }); |
137 | 141 |
|
| 142 | +describe('isPrintableAsBlockString', () => { |
| 143 | + function expectPrintable(str: string) { |
| 144 | + return expect(isPrintableAsBlockString(str)).to.equal(true); |
| 145 | + } |
| 146 | + |
| 147 | + function expectNonPrintable(str: string) { |
| 148 | + return expect(isPrintableAsBlockString(str)).to.equal(false); |
| 149 | + } |
| 150 | + |
| 151 | + it('accepts valid strings', () => { |
| 152 | + expectPrintable(''); |
| 153 | + expectPrintable(' a'); |
| 154 | + expectPrintable('\t"\n"'); |
| 155 | + expectNonPrintable('\t"\n \n\t"'); |
| 156 | + }); |
| 157 | + |
| 158 | + it('rejects strings with only whitespace', () => { |
| 159 | + expectNonPrintable(' '); |
| 160 | + expectNonPrintable('\t'); |
| 161 | + expectNonPrintable('\t '); |
| 162 | + expectNonPrintable(' \t'); |
| 163 | + }); |
| 164 | + |
| 165 | + it('rejects strings with non-printable character', () => { |
| 166 | + expectNonPrintable('\x00'); |
| 167 | + expectNonPrintable('a\x00b'); |
| 168 | + }); |
| 169 | + |
| 170 | + it('rejects strings with non-printable character', () => { |
| 171 | + expectNonPrintable('\x00'); |
| 172 | + expectNonPrintable('a\x00b'); |
| 173 | + }); |
| 174 | + |
| 175 | + it('rejects strings with only empty lines', () => { |
| 176 | + expectNonPrintable('\n'); |
| 177 | + expectNonPrintable('\n\n'); |
| 178 | + expectNonPrintable('\n\n\n'); |
| 179 | + expectNonPrintable(' \n \n'); |
| 180 | + expectNonPrintable('\t\n\t\t\n'); |
| 181 | + }); |
| 182 | + |
| 183 | + it('rejects strings with carriage return', () => { |
| 184 | + expectNonPrintable('\r'); |
| 185 | + expectNonPrintable('\n\r'); |
| 186 | + expectNonPrintable('\r\n'); |
| 187 | + expectNonPrintable('a\rb'); |
| 188 | + }); |
| 189 | + |
| 190 | + it('rejects strings with leading empty lines', () => { |
| 191 | + expectNonPrintable('\na'); |
| 192 | + expectNonPrintable(' \na'); |
| 193 | + expectNonPrintable('\t\na'); |
| 194 | + expectNonPrintable('\n\na'); |
| 195 | + }); |
| 196 | + |
| 197 | + it('rejects strings with leading empty lines', () => { |
| 198 | + expectNonPrintable('a\n'); |
| 199 | + expectNonPrintable('a\n '); |
| 200 | + expectNonPrintable('a\n\t'); |
| 201 | + expectNonPrintable('a\n\n'); |
| 202 | + }); |
| 203 | +}); |
| 204 | + |
138 | 205 | describe('printBlockString', () => { |
139 | 206 | function expectBlockString(str: string) { |
140 | 207 | return { |
|
0 commit comments