UNPKG

1.6 kBJavaScriptView Raw
1'use strict';
2
3var encoding = require('../lib/encoding');
4
5exports['General tests'] = {
6 'From UTF-8 to Latin_1': function (test) {
7 var input = 'ÕÄÖÜ',
8 expected = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc]);
9 test.deepEqual(encoding.convert(input, 'latin1'), expected);
10 test.done();
11 },
12
13 'From Latin_1 to UTF-8': function (test) {
14 var input = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc]),
15 expected = 'ÕÄÖÜ';
16 test.deepEqual(encoding.convert(input, 'utf-8', 'latin1').toString(), expected);
17 test.done();
18 },
19
20 'From UTF-8 to UTF-8': function (test) {
21 var input = 'ÕÄÖÜ',
22 expected = Buffer.from('ÕÄÖÜ');
23 test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8'), expected);
24 test.done();
25 },
26
27 'From Latin_13 to Latin_15': function (test) {
28 var input = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),
29 expected = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc, 0xa6]);
30 test.deepEqual(encoding.convert(input, 'latin_15', 'latin13'), expected);
31 test.done();
32 }
33
34 /*
35 // ISO-2022-JP is not supported by iconv-lite
36 "From ISO-2022-JP to UTF-8 with Iconv": function (test) {
37 var input = Buffer.from(
38 "GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC",
39 "base64"
40 ),
41 expected = Buffer.from(
42 "5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK",
43 "base64"
44 );
45 test.deepEqual(encoding.convert(input, "utf-8", "ISO-2022-JP"), expected);
46 test.done();
47 },
48 */
49};