mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
.
This commit is contained in:
@@ -1337,18 +1337,18 @@ suite('vscode API - workspace', () => {
|
||||
const uri = root.with({ path: posix.join(root.path, 'file.txt') });
|
||||
|
||||
// without setting
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, Buffer.from('Hello World')), 'Hello World');
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, Buffer.from('Hellö Wörld')), 'Hellö Wörld');
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([0xEF, 0xBB, 0xBF, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])), 'Hello World'); // UTF-8 with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([0xFE, 0xFF, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100])), 'Hello World'); // UTF-16 BE with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([0xFF, 0xFE, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0])), 'Hello World'); // UTF-16 LE with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100])), 'Hello World');
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0])), 'Hello World');
|
||||
assert.strictEqual(await vscode.workspace.decode(Buffer.from('Hello World'), uri), 'Hello World');
|
||||
assert.strictEqual(await vscode.workspace.decode(Buffer.from('Hellö Wörld'), uri), 'Hellö Wörld');
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([0xEF, 0xBB, 0xBF, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]), uri), 'Hello World'); // UTF-8 with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([0xFE, 0xFF, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100]), uri), 'Hello World'); // UTF-16 BE with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([0xFF, 0xFE, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0]), uri), 'Hello World'); // UTF-16 LE with BOM
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100]), uri), 'Hello World');
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0]), uri), 'Hello World');
|
||||
|
||||
// with auto-guess encoding
|
||||
try {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('autoGuessEncoding', true, vscode.ConfigurationTarget.Global);
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100])), 'Hellö Wörld');
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100]), uri), 'Hellö Wörld');
|
||||
} finally {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('autoGuessEncoding', false, vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
@@ -1356,7 +1356,7 @@ suite('vscode API - workspace', () => {
|
||||
// with encoding setting
|
||||
try {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'windows1252', vscode.ConfigurationTarget.Global);
|
||||
assert.strictEqual(await vscode.workspace.decode(uri, new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100])), 'Hellö Wörld');
|
||||
assert.strictEqual(await vscode.workspace.decode(new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100]), uri), 'Hellö Wörld');
|
||||
} finally {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'utf8', vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
@@ -1366,21 +1366,21 @@ suite('vscode API - workspace', () => {
|
||||
const uri = root.with({ path: posix.join(root.path, 'file.txt') });
|
||||
|
||||
// without setting
|
||||
assert.strictEqual((await vscode.workspace.encode(uri, 'Hello World')).toString(), 'Hello World');
|
||||
assert.strictEqual((await vscode.workspace.encode('Hello World', uri)).toString(), 'Hello World');
|
||||
|
||||
// with encoding setting
|
||||
try {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'utf8bom', vscode.ConfigurationTarget.Global);
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode(uri, 'Hello World'), new Uint8Array([0xEF, 0xBB, 0xBF, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])));
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode('Hello World', uri), new Uint8Array([0xEF, 0xBB, 0xBF, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])));
|
||||
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'utf16le', vscode.ConfigurationTarget.Global);
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode(uri, 'Hello World'), new Uint8Array([0xFF, 0xFE, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0])));
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode('Hello World', uri), new Uint8Array([0xFF, 0xFE, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0])));
|
||||
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'utf16be', vscode.ConfigurationTarget.Global);
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode(uri, 'Hello World'), new Uint8Array([0xFE, 0xFF, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100])));
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode('Hello World', uri), new Uint8Array([0xFE, 0xFF, 0, 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100])));
|
||||
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'cp1252', vscode.ConfigurationTarget.Global);
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode(uri, 'Hellö Wörld'), new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100])));
|
||||
assert.ok(equalsUint8Array(await vscode.workspace.encode('Hellö Wörld', uri), new Uint8Array([72, 101, 108, 108, 0xF6, 32, 87, 0xF6, 114, 108, 100])));
|
||||
} finally {
|
||||
await vscode.workspace.getConfiguration('files', uri).update('encoding', 'utf8', vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user