node/test/parallel/test-internal-util-normalizeencoding.js
James M Snell 6dd093da26 buffer,string_decoder: consolidate encoding validation logic
Buffer.isEncoding and string_decoder.normalizeEncoding shared
quite a bit of logic. This moves the primary logic into
internal/util. The userland modules that monkey patch Buffer.isEncoding
should still work.

PR-URL: https://github.com/nodejs/node/pull/7207
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-06-21 09:28:38 -07:00

40 lines
814 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const util = require('internal/util');
const tests = [
['', 'utf8'],
['utf8', 'utf8'],
['utf-8', 'utf8'],
['UTF-8', 'utf8'],
['UTF8', 'utf8'],
['Utf8', 'utf8'],
['uTf-8', 'utf8'],
['utF-8', 'utf8'],
['ucs2', 'utf16le'],
['UCS2', 'utf16le'],
['utf16le', 'utf16le'],
['utf-16le', 'utf16le'],
['UTF-16LE', 'utf16le'],
['UTF16LE', 'utf16le'],
['binary', 'latin1'],
['BINARY', 'latin1'],
['latin1', 'latin1'],
['base64', 'base64'],
['BASE64', 'base64'],
['hex', 'hex'],
['HEX', 'hex'],
['foo', undefined],
[1, undefined],
[false, 'utf8'],
[undefined, 'utf8'],
[[], undefined],
];
tests.forEach((i) => {
assert.strictEqual(util.normalizeEncoding(i[0]), i[1]);
});