diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-04-03 18:15:13 -0700 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2017-04-12 10:03:26 -0700 |
commit | 2ced07ccaf7682b9ec8fb3bcc3dc8d2bb2798c61 (patch) | |
tree | 31245a1e2025264acf2216876c9e190addd44287 /test | |
parent | a8f460f12d81f63d95b3f1bc12a89e36cae2b271 (diff) | |
download | node-new-2ced07ccaf7682b9ec8fb3bcc3dc8d2bb2798c61.tar.gz |
zlib: support all ArrayBufferView types
PR-URL: https://github.com/nodejs/node/pull/12223
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-zlib-convenience-methods.js | 26 | ||||
-rw-r--r-- | test/parallel/test-zlib-deflate-constructors.js | 3 | ||||
-rw-r--r-- | test/parallel/test-zlib-dictionary.js | 3 | ||||
-rw-r--r-- | test/parallel/test-zlib-not-string-or-buffer.js | 4 |
4 files changed, 20 insertions, 16 deletions
diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js index df56f21ff4..78bb105906 100644 --- a/test/parallel/test-zlib-convenience-methods.js +++ b/test/parallel/test-zlib-convenience-methods.js @@ -26,24 +26,28 @@ const common = require('../common'); const assert = require('assert'); const zlib = require('zlib'); -const expectStr = 'blahblahblahblahblahblah'; +// Must be a multiple of 4 characters in total to test all ArrayBufferView +// types. +const expectStr = 'blah'.repeat(8); const expectBuf = Buffer.from(expectStr); -const expectUint8Array = new Uint8Array(expectBuf); + const opts = { level: 9, chunkSize: 1024, }; -for (const method of [ - ['gzip', 'gunzip'], - ['gzip', 'unzip'], - ['deflate', 'inflate'], - ['deflateRaw', 'inflateRaw'], +for (const [type, expect] of [ + ['string', expectStr], + ['Buffer', expectBuf], + ...common.getArrayBufferViews(expectBuf).map((obj) => + [obj[Symbol.toStringTag], obj] + ) ]) { - for (const [type, expect] of [ - ['string', expectStr], - ['Buffer', expectBuf], - ['Uint8Array', expectUint8Array] + for (const method of [ + ['gzip', 'gunzip'], + ['gzip', 'unzip'], + ['deflate', 'inflate'], + ['deflateRaw', 'inflateRaw'], ]) { zlib[method[0]](expect, opts, common.mustCall((err, result) => { zlib[method[1]](result, opts, common.mustCall((err, result) => { diff --git a/test/parallel/test-zlib-deflate-constructors.js b/test/parallel/test-zlib-deflate-constructors.js index c495d2d11d..49695fbaa5 100644 --- a/test/parallel/test-zlib-deflate-constructors.js +++ b/test/parallel/test-zlib-deflate-constructors.js @@ -107,5 +107,6 @@ assert.throws( // Throws if opts.dictionary is not a Buffer assert.throws( () => { new zlib.Deflate({dictionary: 'not a buffer'}); }, - /^TypeError: Invalid dictionary: it should be a Buffer or an Uint8Array$/ + new RegExp('^TypeError: Invalid dictionary: it should be a Buffer, ' + + 'TypedArray, or DataView$') ); diff --git a/test/parallel/test-zlib-dictionary.js b/test/parallel/test-zlib-dictionary.js index a3b55bc72d..1662e63bca 100644 --- a/test/parallel/test-zlib-dictionary.js +++ b/test/parallel/test-zlib-dictionary.js @@ -41,7 +41,6 @@ const spdyDict = Buffer.from([ 'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1', '.1statusversionurl\0' ].join('')); -const spdyDictUint8Array = new Uint8Array(spdyDict); const input = [ 'HTTP/1.1 200 Ok', @@ -168,7 +167,7 @@ function deflateRawResetDictionaryTest(spdyDict) { }); } -for (const dict of [spdyDict, spdyDictUint8Array]) { +for (const dict of [spdyDict, ...common.getArrayBufferViews(spdyDict)]) { basicDictionaryTest(dict); deflateResetDictionaryTest(dict); rawDictionaryTest(dict); diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js index 510e111f70..43488f0075 100644 --- a/test/parallel/test-zlib-not-string-or-buffer.js +++ b/test/parallel/test-zlib-not-string-or-buffer.js @@ -7,8 +7,8 @@ require('../common'); const assert = require('assert'); const zlib = require('zlib'); -const expected = - /^TypeError: "buffer" argument must be a string, Buffer, or Uint8Array$/; +const expected = new RegExp('^TypeError: "buffer" argument must be a string, ' + + 'Buffer, TypedArray, or DataView$'); assert.throws(() => { zlib.deflateSync(undefined); }, expected); assert.throws(() => { zlib.deflateSync(null); }, expected); |