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 ['base64url', 'base64url'], 37 ['BASE64url', 'base64url'], 38 ['Base64url', 'base64url'], 39 ['hex', 'hex'], 40 ['HEX', 'hex'], 41 ['ASCII', 'ascii'], 42 ['AsCii', 'ascii'], 43 ['foo', undefined], 44 [1, undefined], 45 [false, undefined], 46 [NaN, undefined], 47 [0, undefined], 48 [[], undefined], 49 [{}, undefined], 50]; 51 52tests.forEach((e, i) => { 53 const res = util.normalizeEncoding(e[0]); 54 assert.strictEqual(res, e[1], `#${i} failed: expected ${e[1]}, got ${res}`); 55}); 56