diff options
author | James M Snell <jasnell@gmail.com> | 2016-06-07 16:03:27 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-06-21 09:28:38 -0700 |
commit | 6dd093da261bc12fe5c2d2669eaca96ef4583f10 (patch) | |
tree | c5e59fdade5983d4b13279aafd5329b5573dd49d /test/parallel/test-internal-util-normalizeencoding.js | |
parent | 193afef3b03ecb65c4905843f4bca7b5d7b2ea31 (diff) | |
download | node-new-6dd093da261bc12fe5c2d2669eaca96ef4583f10.tar.gz |
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>
Diffstat (limited to 'test/parallel/test-internal-util-normalizeencoding.js')
-rw-r--r-- | test/parallel/test-internal-util-normalizeencoding.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-internal-util-normalizeencoding.js b/test/parallel/test-internal-util-normalizeencoding.js new file mode 100644 index 0000000000..9adc3753e8 --- /dev/null +++ b/test/parallel/test-internal-util-normalizeencoding.js @@ -0,0 +1,39 @@ +// 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]); +}); |