mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 01:25:38 -05:00
Merge from master
This commit is contained in:
@@ -3,153 +3,133 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as fs from 'fs';
|
||||
import * as encoding from 'vs/base/node/encoding';
|
||||
import { readExactlyByFile } from 'vs/base/node/stream';
|
||||
import { Readable } from 'stream';
|
||||
import { getPathFromAmdModule } from 'vs/base/common/amd';
|
||||
|
||||
suite('Encoding', () => {
|
||||
test('detectBOM UTF-8', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf8.css');
|
||||
test('detectBOM UTF-8', async () => {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some_utf8.css');
|
||||
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf8');
|
||||
});
|
||||
const detectedEncoding = await encoding.detectEncodingByBOM(file);
|
||||
assert.equal(detectedEncoding, 'utf8');
|
||||
});
|
||||
|
||||
test('detectBOM UTF-16 LE', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf16le.css');
|
||||
test('detectBOM UTF-16 LE', async () => {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some_utf16le.css');
|
||||
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf16le');
|
||||
});
|
||||
const detectedEncoding = await encoding.detectEncodingByBOM(file);
|
||||
assert.equal(detectedEncoding, 'utf16le');
|
||||
});
|
||||
|
||||
test('detectBOM UTF-16 BE', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf16be.css');
|
||||
test('detectBOM UTF-16 BE', async () => {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some_utf16be.css');
|
||||
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf16be');
|
||||
});
|
||||
const detectedEncoding = await encoding.detectEncodingByBOM(file);
|
||||
assert.equal(detectedEncoding, 'utf16be');
|
||||
});
|
||||
|
||||
test('detectBOM ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/some_ansi.css');
|
||||
test('detectBOM ANSI', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some_ansi.css');
|
||||
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, null);
|
||||
});
|
||||
const detectedEncoding = await encoding.detectEncodingByBOM(file);
|
||||
assert.equal(detectedEncoding, null);
|
||||
});
|
||||
|
||||
test('detectBOM ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/empty.txt');
|
||||
test('detectBOM ANSI', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/empty.txt');
|
||||
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, null);
|
||||
});
|
||||
const detectedEncoding = await encoding.detectEncodingByBOM(file);
|
||||
assert.equal(detectedEncoding, null);
|
||||
});
|
||||
|
||||
test('resolve terminal encoding (detect)', function () {
|
||||
return encoding.resolveTerminalEncoding().then(enc => {
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
});
|
||||
test('resolve terminal encoding (detect)', async function () {
|
||||
const enc = await encoding.resolveTerminalEncoding();
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
});
|
||||
|
||||
test('resolve terminal encoding (environment)', function () {
|
||||
test('resolve terminal encoding (environment)', async function () {
|
||||
process.env['VSCODE_CLI_ENCODING'] = 'utf16le';
|
||||
|
||||
return encoding.resolveTerminalEncoding().then(enc => {
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
assert.equal(enc, 'utf16le');
|
||||
});
|
||||
const enc = await encoding.resolveTerminalEncoding();
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
assert.equal(enc, 'utf16le');
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (JSON saved as PNG)', function () {
|
||||
const file = require.toUrl('./fixtures/some.json.png');
|
||||
test('detectEncodingFromBuffer (JSON saved as PNG)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.json.png');
|
||||
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (PNG saved as TXT)', function () {
|
||||
const file = require.toUrl('./fixtures/some.png.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
test('detectEncodingFromBuffer (PNG saved as TXT)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.png.txt');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (XML saved as PNG)', function () {
|
||||
const file = require.toUrl('./fixtures/some.xml.png');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
test('detectEncodingFromBuffer (XML saved as PNG)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.xml.png');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (QWOFF saved as TXT)', function () {
|
||||
const file = require.toUrl('./fixtures/some.qwoff.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
test('detectEncodingFromBuffer (QWOFF saved as TXT)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.qwoff.txt');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (CSS saved as QWOFF)', function () {
|
||||
const file = require.toUrl('./fixtures/some.css.qwoff');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
test('detectEncodingFromBuffer (CSS saved as QWOFF)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.css.qwoff');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (PDF)', function () {
|
||||
const file = require.toUrl('./fixtures/some.pdf');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
test('detectEncodingFromBuffer (PDF)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.pdf');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (guess UTF-16 LE from content without BOM)', function () {
|
||||
const file = require.toUrl('./fixtures/utf16_le_nobom.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16le);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
test('detectEncodingFromBuffer (guess UTF-16 LE from content without BOM)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/utf16_le_nobom.txt');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16le);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (guess UTF-16 BE from content without BOM)', function () {
|
||||
const file = require.toUrl('./fixtures/utf16_be_nobom.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16be);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
test('detectEncodingFromBuffer (guess UTF-16 BE from content without BOM)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/utf16_be_nobom.txt');
|
||||
const buffer = await readExactlyByFile(file, 512);
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16be);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (ShiftJIS)', function () {
|
||||
const file = require.toUrl('./fixtures/some.shiftjis.txt');
|
||||
return readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
return encoding.detectEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'shiftjis');
|
||||
});
|
||||
});
|
||||
test('autoGuessEncoding (ShiftJIS)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.shiftjis.txt');
|
||||
const buffer = await readExactlyByFile(file, 512 * 8);
|
||||
const mimes = await encoding.detectEncodingFromBuffer(buffer, true);
|
||||
assert.equal(mimes.encoding, 'shiftjis');
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (CP1252)', function () {
|
||||
const file = require.toUrl('./fixtures/some.cp1252.txt');
|
||||
return readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
return encoding.detectEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'windows1252');
|
||||
});
|
||||
});
|
||||
test('autoGuessEncoding (CP1252)', async function () {
|
||||
const file = getPathFromAmdModule(require, './fixtures/some.cp1252.txt');
|
||||
const buffer = await readExactlyByFile(file, 512 * 8);
|
||||
const mimes = await encoding.detectEncodingFromBuffer(buffer, true);
|
||||
assert.equal(mimes.encoding, 'windows1252');
|
||||
});
|
||||
|
||||
async function readAndDecodeFromDisk(path, _encoding) {
|
||||
@@ -238,7 +218,7 @@ suite('Encoding', () => {
|
||||
|
||||
test('toDecodeStream - encoding, utf16be', async function () {
|
||||
|
||||
let path = require.toUrl('./fixtures/some_utf16be.css');
|
||||
let path = getPathFromAmdModule(require, './fixtures/some_utf16be.css');
|
||||
let source = fs.createReadStream(path);
|
||||
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, { minBytesRequiredForDetection: 64 });
|
||||
@@ -254,7 +234,7 @@ suite('Encoding', () => {
|
||||
|
||||
test('toDecodeStream - empty file', async function () {
|
||||
|
||||
let path = require.toUrl('./fixtures/empty.txt');
|
||||
let path = getPathFromAmdModule(require, './fixtures/empty.txt');
|
||||
let source = fs.createReadStream(path);
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, {});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user