Use canonical uri for openTextDocument api, #93368

This commit is contained in:
Johannes Rieken
2020-05-29 18:16:21 +02:00
parent 4d854d4c89
commit b0d056202b
9 changed files with 94 additions and 34 deletions

View File

@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled } from '../utils';
import { join, posix, basename } from 'path';
import * as fs from 'fs';
import { TestFS } from '../memfs';
suite('vscode API - workspace', () => {
@@ -163,6 +164,40 @@ suite('vscode API - workspace', () => {
});
});
test('openTextDocument, actual casing first', async function () {
const fs = new TestFS('this-fs', false);
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isCaseSensitive: fs.isCaseSensitive });
let uriOne = vscode.Uri.parse('this-fs:/one');
let uriTwo = vscode.Uri.parse('this-fs:/two');
let uriONE = vscode.Uri.parse('this-fs:/ONE'); // same resource, different uri
let uriTWO = vscode.Uri.parse('this-fs:/TWO');
fs.writeFile(uriOne, Buffer.from('one'), { create: true, overwrite: true });
fs.writeFile(uriTwo, Buffer.from('two'), { create: true, overwrite: true });
// lower case (actual case) comes first
let docOne = await vscode.workspace.openTextDocument(uriOne);
assert.equal(docOne.uri.toString(), uriOne.toString());
let docONE = await vscode.workspace.openTextDocument(uriONE);
assert.equal(docONE === docOne, true);
assert.equal(docONE.uri.toString(), uriOne.toString());
assert.equal(docONE.uri.toString() !== uriONE.toString(), true); // yep
// upper case (NOT the actual case) comes first
let docTWO = await vscode.workspace.openTextDocument(uriTWO);
assert.equal(docTWO.uri.toString(), uriTWO.toString());
let docTwo = await vscode.workspace.openTextDocument(uriTwo);
assert.equal(docTWO === docTwo, true);
assert.equal(docTwo.uri.toString(), uriTWO.toString());
assert.equal(docTwo.uri.toString() !== uriTwo.toString(), true); // yep
reg.dispose();
});
test('eol, read', () => {
const a = createRandomFile('foo\nbar\nbar').then(file => {
return vscode.workspace.openTextDocument(file).then(doc => {