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

'use strict';

import assert = require('assert');

import encoding = require('vs/base/node/encoding');

suite('Encoding', () => {
K
katainaka0503 已提交
13
	test('detectBOM UTF-8', (done: (err?: any) => void) => {
14
		const file = require.toUrl('./fixtures/some_utf8.css');
E
Erich Gamma 已提交
15

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

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

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

K
katainaka0503 已提交
31
	test('detectBOM UTF-16 BE', (done: (err?: any) => void) => {
32
		const file = require.toUrl('./fixtures/some_utf16be.css');
E
Erich Gamma 已提交
33

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

K
katainaka0503 已提交
40
	test('detectBOM ANSI', function (done: (err?: any) => void) {
41
		const file = require.toUrl('./fixtures/some_ansi.css');
E
Erich Gamma 已提交
42

K
katainaka0503 已提交
43
		encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
44 45
			assert.equal(encoding, null);
			done();
K
katainaka0503 已提交
46
		}, done);
E
Erich Gamma 已提交
47 48
	});

K
katainaka0503 已提交
49
	test('detectBOM ANSI', function (done: (err?: any) => void) {
50
		const file = require.toUrl('./fixtures/empty.txt');
E
Erich Gamma 已提交
51

K
katainaka0503 已提交
52
		encoding.detectEncodingByBOM(file).then((encoding: string) => {
E
Erich Gamma 已提交
53 54
			assert.equal(encoding, null);
			done();
K
katainaka0503 已提交
55
		}, done);
E
Erich Gamma 已提交
56 57
	});
});