|
2 | 2 | Disposable,
|
3 | 3 | DisposableCollection,
|
4 | 4 | } from '@theia/core/lib/common/disposable';
|
| 5 | +import { isWindows } from '@theia/core/lib/common/os'; |
5 | 6 | import { FileUri } from '@theia/core/lib/node/file-uri';
|
6 | 7 | import { Container } from '@theia/core/shared/inversify';
|
7 | 8 | import { expect } from 'chai';
|
@@ -226,16 +227,94 @@ describe('sketches-service-impl', () => {
|
226 | 227 | expect(mainFileContentOneAfterCopy).to.be.equal(contentOne);
|
227 | 228 | expect(mainFileContentTwoAfterCopy).to.be.equal(contentOne);
|
228 | 229 | });
|
| 230 | + |
| 231 | + ( |
| 232 | + [ |
| 233 | + ['(', ')', 'parentheses'], |
| 234 | + ['[', ']', 'brackets'], |
| 235 | + ['{', '}', 'braces'], |
| 236 | + [ |
| 237 | + '<', |
| 238 | + '>', |
| 239 | + 'chevrons', |
| 240 | + { |
| 241 | + predicate: () => isWindows, |
| 242 | + why: '< (less than) and > (greater than) are reserved characters on Windows (https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions)', |
| 243 | + }, |
| 244 | + ], |
| 245 | + ] as [ |
| 246 | + open: string, |
| 247 | + close: string, |
| 248 | + name: string, |
| 249 | + skip?: { predicate: () => boolean; why: string } |
| 250 | + ][] |
| 251 | + ).map(([open, close, name, skip]) => |
| 252 | + it(`should copy a sketch when the path contains ${name} in the sketch folder path: '${open},${close}'`, async function () { |
| 253 | + if (skip) { |
| 254 | + const { predicate, why } = skip; |
| 255 | + if (predicate()) { |
| 256 | + console.info(why); |
| 257 | + return this.skip(); |
| 258 | + } |
| 259 | + } |
| 260 | + this.timeout(testTimeout); |
| 261 | + const sketchesService = |
| 262 | + container.get<SketchesServiceImpl>(SketchesService); |
| 263 | + const content = `// special content when ${name} are in the path`; |
| 264 | + const tempRoot = await sketchesService['createTempFolder'](); |
| 265 | + toDispose.push(disposeFolder(tempRoot)); |
| 266 | + const sketch = await sketchesService.createNewSketch( |
| 267 | + 'punctuation_marks', |
| 268 | + content |
| 269 | + ); |
| 270 | + toDispose.push(disposeSketch(sketch)); |
| 271 | + |
| 272 | + // the destination path contains punctuation marks |
| 273 | + const tempRootUri = FileUri.create(tempRoot); |
| 274 | + const testSegment = `path segment with ${open}${name}${close}`; |
| 275 | + const firstDestinationUri = tempRootUri |
| 276 | + .resolve(testSegment) |
| 277 | + .resolve('first') |
| 278 | + .resolve(sketch.name); |
| 279 | + |
| 280 | + const firstSketchCopy = await sketchesService.copy(sketch, { |
| 281 | + destinationUri: firstDestinationUri.toString(), |
| 282 | + }); |
| 283 | + expect(firstSketchCopy).to.be.not.undefined; |
| 284 | + expect(firstSketchCopy.mainFileUri).to.be.equal( |
| 285 | + firstDestinationUri.resolve(`${sketch.name}.ino`).toString() |
| 286 | + ); |
| 287 | + const firstCopyContent = await mainFileContentOf(firstSketchCopy); |
| 288 | + expect(firstCopyContent).to.be.equal(content); |
| 289 | + |
| 290 | + // the source path contains punctuation marks. yes, the target too, but it does not matter |
| 291 | + const secondDestinationUri = tempRootUri |
| 292 | + .resolve(testSegment) |
| 293 | + .resolve('second') |
| 294 | + .resolve(sketch.name); |
| 295 | + const secondSketchCopy = await sketchesService.copy(firstSketchCopy, { |
| 296 | + destinationUri: secondDestinationUri.toString(), |
| 297 | + }); |
| 298 | + expect(secondSketchCopy).to.be.not.undefined; |
| 299 | + expect(secondSketchCopy.mainFileUri).to.be.equal( |
| 300 | + secondDestinationUri.resolve(`${sketch.name}.ino`).toString() |
| 301 | + ); |
| 302 | + const secondCopyContent = await mainFileContentOf(secondSketchCopy); |
| 303 | + expect(secondCopyContent).to.be.equal(content); |
| 304 | + }) |
| 305 | + ); |
229 | 306 | });
|
230 | 307 | });
|
231 | 308 |
|
232 | 309 | function disposeSketch(...sketch: Sketch[]): Disposable {
|
| 310 | + return disposeFolder(...sketch.map(({ uri }) => FileUri.fsPath(uri))); |
| 311 | +} |
| 312 | + |
| 313 | +function disposeFolder(...paths: string[]): Disposable { |
233 | 314 | return new DisposableCollection(
|
234 |
| - ...sketch |
235 |
| - .map(({ uri }) => FileUri.fsPath(uri)) |
236 |
| - .map((path) => |
237 |
| - Disposable.create(() => rimrafSync(path, { maxBusyTries: 5 })) |
238 |
| - ) |
| 315 | + ...paths.map((path) => |
| 316 | + Disposable.create(() => rimrafSync(path, { maxBusyTries: 5 })) |
| 317 | + ) |
239 | 318 | );
|
240 | 319 | }
|
241 | 320 |
|
|
0 commit comments