diff options
author | David Cai <davidcai1993@yahoo.com> | 2017-05-05 15:08:59 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-07 22:20:33 +0200 |
commit | a710e443a28552dece3453ab7b7b8306489ecf85 (patch) | |
tree | e5d21ab220644ac9d7fef73c31a9d0326d036cfa /test/parallel/test-buffer-tostring.js | |
parent | 7e5f500c9861708e221e1e5e1d42e92af234583b (diff) | |
download | node-new-a710e443a28552dece3453ab7b7b8306489ecf85.tar.gz |
test: complete coverage of buffer
PR-URL: https://github.com/nodejs/node/pull/12831
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-tostring.js')
-rw-r--r-- | test/parallel/test-buffer-tostring.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/test/parallel/test-buffer-tostring.js b/test/parallel/test-buffer-tostring.js index 776b7c0892..214d1013e9 100644 --- a/test/parallel/test-buffer-tostring.js +++ b/test/parallel/test-buffer-tostring.js @@ -4,8 +4,8 @@ require('../common'); const assert = require('assert'); // utf8, ucs2, ascii, latin1, utf16le -const encodings = ['utf8', 'ucs2', 'ucs-2', 'ascii', 'latin1', 'binary', - 'utf16le', 'utf-16le']; +const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1', + 'binary', 'utf16le', 'utf-16le']; encodings .reduce((es, e) => es.concat(e, e.toUpperCase()), []) @@ -23,3 +23,12 @@ encodings assert.strictEqual(Buffer.from('666f6f', encoding).toString(encoding), '666f6f'); }); + +// Invalid encodings +for (let i = 1; i < 10; i++) { + const encoding = String(i).repeat(i); + const error = new RegExp(`^TypeError: Unknown encoding: ${encoding}$`); + + assert.ok(!Buffer.isEncoding(encoding)); + assert.throws(() => Buffer.from('foo').toString(encoding), error); +} |