encoding.test.ts 2.0 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

8
import assert = require('assert');
E
Erich Gamma 已提交
9

10 11
import encoding = require('vs/base/node/encoding');
import { encodingExists } from 'vs/base/node/encoding';
E
Erich Gamma 已提交
12 13

suite('Encoding', () => {
14
	test('detectBOM UTF-8', () => {
15
		const file = require.toUrl('./fixtures/some_utf8.css');
E
Erich Gamma 已提交
16

17
		return encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
18
			assert.equal(encoding, 'utf8');
19
		});
E
Erich Gamma 已提交
20 21
	});

22
	test('detectBOM UTF-16 LE', () => {
23
		const file = require.toUrl('./fixtures/some_utf16le.css');
E
Erich Gamma 已提交
24

25
		return encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
26
			assert.equal(encoding, 'utf16le');
27
		});
E
Erich Gamma 已提交
28 29
	});

30
	test('detectBOM UTF-16 BE', () => {
31
		const file = require.toUrl('./fixtures/some_utf16be.css');
E
Erich Gamma 已提交
32

33
		return encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
34
			assert.equal(encoding, 'utf16be');
35
		});
E
Erich Gamma 已提交
36 37
	});

38
	test('detectBOM ANSI', function () {
39
		const file = require.toUrl('./fixtures/some_ansi.css');
E
Erich Gamma 已提交
40

41
		return encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
42
			assert.equal(encoding, null);
43
		});
E
Erich Gamma 已提交
44 45
	});

46
	test('detectBOM ANSI', function () {
47
		const file = require.toUrl('./fixtures/empty.txt');
E
Erich Gamma 已提交
48

49
		return encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
50
			assert.equal(encoding, null);
51
		});
E
Erich Gamma 已提交
52
	});
53

54
	test('resolve terminal encoding (detect)', function () {
55 56
		return encoding.resolveTerminalEncoding().then(encoding => {
			assert.ok(encodingExists(encoding));
57
		});
58 59
	});

60
	test('resolve terminal encoding (environment)', function () {
61 62
		process.env['VSCODE_CLI_ENCODING'] = 'utf16le';

63 64 65
		return encoding.resolveTerminalEncoding().then(encoding => {
			assert.ok(encodingExists(encoding));
			assert.equal(encoding, 'utf16le');
66
		});
67
	});
E
Erich Gamma 已提交
68
});