1// Flags: --expose-internals 2'use strict'; 3 4require('../common'); 5const assert = require('assert'); 6const util = require('internal/util'); 7 8const tests = [ 9 [undefined, 'utf8'], 10 [null, 'utf8'], 11 ['', 'utf8'], 12 ['utf8', 'utf8'], 13 ['utf-8', 'utf8'], 14 ['UTF-8', 'utf8'], 15 ['UTF8', 'utf8'], 16 ['Utf8', 'utf8'], 17 ['uTf-8', 'utf8'], 18 ['utF-8', 'utf8'], 19 ['ucs2', 'utf16le'], 20 ['UCS2', 'utf16le'], 21 ['UcS2', 'utf16le'], 22 ['ucs-2', 'utf16le'], 23 ['UCS-2', 'utf16le'], 24 ['UcS-2', 'utf16le'], 25 ['utf16le', 'utf16le'], 26 ['utf-16le', 'utf16le'], 27 ['UTF-16LE', 'utf16le'], 28 ['UTF16LE', 'utf16le'], 29 ['binary', 'latin1'], 30 ['BINARY', 'latin1'], 31 ['latin1', 'latin1'], 32 ['LaTiN1', 'latin1'], 33 ['base64', 'base64'], 34 ['BASE64', 'base64'], 35 ['Base64', 'base64'], 36 ['hex', 'hex'], 37 ['HEX', 'hex'], 38 ['ASCII', 'ascii'], 39 ['AsCii', 'ascii'], 40 ['foo', undefined], 41 [1, undefined], 42 [false, undefined], 43 [NaN, undefined], 44 [0, undefined], 45 [[], undefined], 46 [{}, undefined] 47]; 48 49tests.forEach((e, i) => { 50 const res = util.normalizeEncoding(e[0]); 51 assert.strictEqual(res, e[1], `#${i} failed: expected ${e[1]}, got ${res}`); 52}); 53