• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4// This tests internal mapping of the Node.js encoding implementation
5
6require('../common');
7
8const assert = require('assert');
9const { getEncodingFromLabel } = require('internal/encoding');
10
11// Test Encoding Mappings
12{
13  const mappings = {
14    'utf-8': [
15      'unicode-1-1-utf-8',
16      'utf8',
17    ],
18    'utf-16be': [],
19    'utf-16le': [
20      'utf-16',
21    ],
22    'ibm866': [
23      '866',
24      'cp866',
25      'csibm866',
26    ],
27    'iso-8859-2': [
28      'csisolatin2',
29      'iso-ir-101',
30      'iso8859-2',
31      'iso88592',
32      'iso_8859-2',
33      'iso_8859-2:1987',
34      'l2',
35      'latin2',
36    ],
37    'iso-8859-3': [
38      'csisolatin3',
39      'iso-ir-109',
40      'iso8859-3',
41      'iso88593',
42      'iso_8859-3',
43      'iso_8859-3:1988',
44      'l3',
45      'latin3',
46    ],
47    'iso-8859-4': [
48      'csisolatin4',
49      'iso-ir-110',
50      'iso8859-4',
51      'iso88594',
52      'iso_8859-4',
53      'iso_8859-4:1988',
54      'l4',
55      'latin4',
56    ],
57    'iso-8859-5': [
58      'csisolatincyrillic',
59      'cyrillic',
60      'iso-ir-144',
61      'iso8859-5',
62      'iso88595',
63      'iso_8859-5',
64      'iso_8859-5:1988',
65    ],
66    'iso-8859-6': [
67      'arabic',
68      'asmo-708',
69      'csiso88596e',
70      'csiso88596i',
71      'csisolatinarabic',
72      'ecma-114',
73      'iso-8859-6-e',
74      'iso-8859-6-i',
75      'iso-ir-127',
76      'iso8859-6',
77      'iso88596',
78      'iso_8859-6',
79      'iso_8859-6:1987',
80    ],
81    'iso-8859-7': [
82      'csisolatingreek',
83      'ecma-118',
84      'elot_928',
85      'greek',
86      'greek8',
87      'iso-ir-126',
88      'iso8859-7',
89      'iso88597',
90      'iso_8859-7',
91      'iso_8859-7:1987',
92      'sun_eu_greek',
93    ],
94    'iso-8859-8': [
95      'csiso88598e',
96      'csisolatinhebrew',
97      'hebrew',
98      'iso-8859-8-e',
99      'iso-ir-138',
100      'iso8859-8',
101      'iso88598',
102      'iso_8859-8',
103      'iso_8859-8:1988',
104      'visual',
105    ],
106    'iso-8859-8-i': [
107      'csiso88598i',
108      'logical',
109    ],
110    'iso-8859-10': [
111      'csisolatin6',
112      'iso-ir-157',
113      'iso8859-10',
114      'iso885910',
115      'l6',
116      'latin6',
117    ],
118    'iso-8859-13': [
119      'iso8859-13',
120      'iso885913',
121    ],
122    'iso-8859-14': [
123      'iso8859-14',
124      'iso885914',
125    ],
126    'iso-8859-15': [
127      'csisolatin9',
128      'iso8859-15',
129      'iso885915',
130      'iso_8859-15',
131      'l9',
132    ],
133    'koi8-r': [
134      'cskoi8r',
135      'koi',
136      'koi8',
137      'koi8_r',
138    ],
139    'koi8-u': [
140      'koi8-ru',
141    ],
142    'macintosh': [
143      'csmacintosh',
144      'mac',
145      'x-mac-roman',
146    ],
147    'windows-874': [
148      'dos-874',
149      'iso-8859-11',
150      'iso8859-11',
151      'iso885911',
152      'tis-620',
153    ],
154    'windows-1250': [
155      'cp1250',
156      'x-cp1250',
157    ],
158    'windows-1251': [
159      'cp1251',
160      'x-cp1251',
161    ],
162    'windows-1252': [
163      'ansi_x3.4-1968',
164      'ascii',
165      'cp1252',
166      'cp819',
167      'csisolatin1',
168      'ibm819',
169      'iso-8859-1',
170      'iso-ir-100',
171      'iso8859-1',
172      'iso88591',
173      'iso_8859-1',
174      'iso_8859-1:1987',
175      'l1',
176      'latin1',
177      'us-ascii',
178      'x-cp1252',
179    ],
180    'windows-1253': [
181      'cp1253',
182      'x-cp1253',
183    ],
184    'windows-1254': [
185      'cp1254',
186      'csisolatin5',
187      'iso-8859-9',
188      'iso-ir-148',
189      'iso8859-9',
190      'iso88599',
191      'iso_8859-9',
192      'iso_8859-9:1989',
193      'l5',
194      'latin5',
195      'x-cp1254',
196    ],
197    'windows-1255': [
198      'cp1255',
199      'x-cp1255',
200    ],
201    'windows-1256': [
202      'cp1256',
203      'x-cp1256',
204    ],
205    'windows-1257': [
206      'cp1257',
207      'x-cp1257',
208    ],
209    'windows-1258': [
210      'cp1258',
211      'x-cp1258',
212    ],
213    'x-mac-cyrillic': [
214      'x-mac-ukrainian',
215    ],
216    'gbk': [
217      'chinese',
218      'csgb2312',
219      'csiso58gb231280',
220      'gb2312',
221      'gb_2312',
222      'gb_2312-80',
223      'iso-ir-58',
224      'x-gbk',
225    ],
226    'gb18030': [ ],
227    'big5': [
228      'big5-hkscs',
229      'cn-big5',
230      'csbig5',
231      'x-x-big5',
232    ],
233    'euc-jp': [
234      'cseucpkdfmtjapanese',
235      'x-euc-jp',
236    ],
237    'iso-2022-jp': [
238      'csiso2022jp',
239    ],
240    'shift_jis': [
241      'csshiftjis',
242      'ms932',
243      'ms_kanji',
244      'shift-jis',
245      'sjis',
246      'windows-31j',
247      'x-sjis',
248    ],
249    'euc-kr': [
250      '  euc-kr  \t',
251      'EUC-kr  \n',
252      'cseuckr',
253      'csksc56011987',
254      'iso-ir-149',
255      'korean',
256      'ks_c_5601-1987',
257      'ks_c_5601-1989',
258      'ksc5601',
259      'ksc_5601',
260      'windows-949',
261    ]
262  };
263  Object.entries(mappings).forEach((i) => {
264    const enc = i[0];
265    const labels = i[1];
266    assert.strictEqual(getEncodingFromLabel(enc), enc);
267    labels.forEach((l) => assert.strictEqual(getEncodingFromLabel(l), enc));
268  });
269
270  assert.strictEqual(getEncodingFromLabel('made-up'), undefined);
271}
272