summaryrefslogtreecommitdiff
path: root/test/parallel/test-internal-util-normalizeencoding.js
blob: d7a0259ac9c9fd54ac61a4fc42e2b432cd8aef6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Flags: --expose-internals
'use strict';

require('../common');
const assert = require('assert');
const util = require('internal/util');

const tests = [
  [undefined, 'utf8'],
  [null, 'utf8'],
  ['', 'utf8'],
  ['utf8', 'utf8'],
  ['utf-8', 'utf8'],
  ['UTF-8', 'utf8'],
  ['UTF8', 'utf8'],
  ['Utf8', 'utf8'],
  ['uTf-8', 'utf8'],
  ['utF-8', 'utf8'],
  ['ucs2', 'utf16le'],
  ['UCS2', 'utf16le'],
  ['UcS2', 'utf16le'],
  ['ucs-2', 'utf16le'],
  ['UCS-2', 'utf16le'],
  ['UcS-2', 'utf16le'],
  ['utf16le', 'utf16le'],
  ['utf-16le', 'utf16le'],
  ['UTF-16LE', 'utf16le'],
  ['UTF16LE', 'utf16le'],
  ['binary', 'latin1'],
  ['BINARY', 'latin1'],
  ['latin1', 'latin1'],
  ['LaTiN1', 'latin1'],
  ['base64', 'base64'],
  ['BASE64', 'base64'],
  ['Base64', 'base64'],
  ['hex', 'hex'],
  ['HEX', 'hex'],
  ['ASCII', 'ascii'],
  ['AsCii', 'ascii'],
  ['foo', undefined],
  [1, undefined],
  [false, undefined],
  [NaN, undefined],
  [0, undefined],
  [[], undefined],
  [{}, undefined]
];

tests.forEach((e, i) => {
  const res = util.normalizeEncoding(e[0]);
  assert.strictEqual(res, e[1], `#${i} failed: expected ${e[1]}, got ${res}`);
});