Cleanup tests

This commit is contained in:
Vitaly Puzrin 2020-11-07 21:00:55 +03:00
parent f5c3c29848
commit 9f5e7dcefc
11 changed files with 63 additions and 115 deletions

View file

@ -35,7 +35,6 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"buffer-from": "^1.1.1",
"eslint": "^7.13.0",
"gh-pages": "^3.1.0",
"mocha": "^8.2.1",

2
test/.eslintrc.yml Normal file
View file

@ -0,0 +1,2 @@
env:
mocha: true

View file

@ -1,13 +1,8 @@
/*global describe, it*/
'use strict';
var assert = require('assert');
var helpers = require('./helpers');
var pako = require('../index');
@ -47,8 +42,8 @@ function testChunk(buf, expected, packer, chunkSize) {
expFlushCount = Math.ceil(packer.result.length / 16384);
assert(!packer.err, 'Packer error: ' + packer.err);
assert(helpers.cmpBuf(packer.result, expected), 'Result is different');
assert.equal(flushCount, expFlushCount, 'onData called ' + flushCount + 'times, expected: ' + expFlushCount);
assert.deepStrictEqual(packer.result, expected);
assert.strictEqual(flushCount, expFlushCount, 'onData called ' + flushCount + 'times, expected: ' + expFlushCount);
}
describe('Small input chunks', function () {
@ -89,7 +84,7 @@ describe('Dummy push (force end)', function () {
deflator.push(data);
deflator.push([], true);
assert(helpers.cmpBuf(deflator.result, pako.deflate(data)));
assert.deepStrictEqual(deflator.result, pako.deflate(data));
});
it('inflate end', function () {
@ -99,7 +94,7 @@ describe('Dummy push (force end)', function () {
inflator.push(data);
inflator.push([], true);
assert(helpers.cmpBuf(inflator.result, pako.inflate(data)));
assert.deepStrictEqual(inflator.result, pako.inflate(data));
});
});
@ -127,7 +122,7 @@ describe('Edge condition', function () {
inflator.push(new Uint8Array(0), true);
assert.ok(!inflator.err, 'Inflate failed with status ' + inflator.err);
assert(helpers.cmpBuf(data, inflator.result));
assert.deepStrictEqual(data, inflator.result);
});
});

View file

@ -1,6 +1,3 @@
/*global describe, it*/
'use strict';
@ -12,8 +9,6 @@ var testSamples = helpers.testSamples;
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var b = require('buffer-from');
var samples = helpers.loadSamples();
@ -179,7 +174,7 @@ describe('Deflate RAW', function () {
describe('Deflate dictionary', function () {
it('trivial dictionary', function () {
var dict = b('abcdefghijklmnoprstuvwxyz');
var dict = Buffer.from('abcdefghijklmnoprstuvwxyz');
testSamples(zlib.deflateSync, pako.deflate, samples, { dictionary: dict });
});
@ -190,20 +185,21 @@ describe('Deflate dictionary', function () {
});
it('handles multiple pushes', function () {
var dict = b('abcd');
var dict = Buffer.from('abcd');
var deflate = new pako.Deflate({ dictionary: dict });
deflate.push(b('hello'), false);
deflate.push(b('hello'), false);
deflate.push(b(' world'), true);
deflate.push(Buffer.from('hello'), false);
deflate.push(Buffer.from('hello'), false);
deflate.push(Buffer.from(' world'), true);
if (deflate.err) { throw new Error(deflate.err); }
var uncompressed = pako.inflate(b(deflate.result), { dictionary: dict });
var uncompressed = pako.inflate(Buffer.from(deflate.result), { dictionary: dict });
if (!helpers.cmpBuf(b('hellohello world'), uncompressed)) {
throw new Error('Result not equal for p -> z');
}
assert.deepStrictEqual(
new Uint8Array(Buffer.from('hellohello world')),
uncompressed
);
});
});
@ -215,6 +211,6 @@ describe('Deflate issues', function () {
var deflatedPakoData = pako.deflate(data, { memLevel: 1 });
var inflatedPakoData = pako.inflate(deflatedPakoData);
assert.equal(data.length, inflatedPakoData.length);
assert.strictEqual(data.length, inflatedPakoData.length);
});
});

View file

@ -1,8 +1,4 @@
// Deflate coverage tests
/*global describe, it*/
'use strict';
@ -26,7 +22,7 @@ function testDeflate(data, opts, flush) {
deflator.push(data, flush);
deflator.push(data, true);
assert.equal(deflator.err, false, msg[deflator.err]);
assert.strictEqual(deflator.err, 0, msg[deflator.err]);
}
describe('Deflate support', function () {

View file

@ -1,6 +1,3 @@
/*global describe, it*/
'use strict';
@ -9,7 +6,6 @@ var path = require('path');
var assert = require('assert');
var pako = require('../index');
var cmp = require('./helpers').cmpBuf;
function a2s(array) {
@ -24,9 +20,9 @@ describe('Gzip special cases', function () {
var inflator = new pako.Inflate();
inflator.push(data, true);
assert.equal(inflator.header.name, 'test name');
assert.equal(inflator.header.comment, 'test comment');
assert.equal(a2s(inflator.header.extra), 'test extra');
assert.strictEqual(inflator.header.name, 'test name');
assert.strictEqual(inflator.header.comment, 'test comment');
assert.strictEqual(a2s(inflator.header.extra), 'test extra');
});
it('Write custom headers', function () {
@ -48,15 +44,15 @@ describe('Gzip special cases', function () {
var inflator = new pako.Inflate({ to: 'string' });
inflator.push(deflator.result, true);
assert.equal(inflator.err, 0);
assert.equal(inflator.result, data);
assert.strictEqual(inflator.err, 0);
assert.strictEqual(inflator.result, data);
var header = inflator.header;
assert.equal(header.time, 1234567);
assert.equal(header.os, 15);
assert.equal(header.name, 'test name');
assert.equal(header.comment, 'test comment');
assert(cmp(header.extra, [ 4, 5, 6 ]));
assert.strictEqual(header.time, 1234567);
assert.strictEqual(header.os, 15);
assert.strictEqual(header.name, 'test name');
assert.strictEqual(header.comment, 'test comment');
assert.deepStrictEqual(header.extra, new Uint8Array([ 4, 5, 6 ]));
});
it('Read stream with SYNC marks', function () {

View file

@ -4,7 +4,6 @@
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var b = require('buffer-from');
var pako = require('../index');
@ -30,24 +29,6 @@ function loadSamples(subdir) {
}
// Compare 2 buffers (can be Array, Uint8Array, Buffer).
//
function cmpBuf(a, b) {
if (a.length !== b.length) {
return false;
}
for (var i = 0, l = a.length; i < l; i++) {
if (a[i] !== b[i]) {
//console.log('pos: ' +i+ ' - ' + a[i].toString(16) + '/' + b[i].toString(16));
return false;
}
}
return true;
}
// Helper to test deflate/inflate with different options.
// Use zlib streams, because it's the only way to define options.
//
@ -57,7 +38,7 @@ function testSingle(zlib_method, pako_method, data, options) {
// hack for testing negative windowBits
if (zlib_options.windowBits < 0) { zlib_options.windowBits = -zlib_options.windowBits; }
var zlib_result = zlib_method(b(data), zlib_options);
var zlib_result = zlib_method(data, zlib_options);
var pako_result = pako_method(data, options);
// One more hack: gzip header contains OS code, that can vary.
@ -65,7 +46,7 @@ function testSingle(zlib_method, pako_method, data, options) {
// position (= no additional gzip headers used)
if (options.ignore_os) zlib_result[9] = pako_result[9];
assert.deepEqual(new Uint8Array(pako_result), zlib_result);
assert.deepStrictEqual(pako_result, new Uint8Array(zlib_result));
}
@ -91,12 +72,11 @@ function testInflate(samples, inflateOptions, deflateOptions) {
deflated = pako.deflate(data, deflateOptions);
inflated = pako.inflate(deflated, inflateOptions);
assert.deepEqual(inflated, data);
assert.deepStrictEqual(inflated, data);
}
}
exports.cmpBuf = cmpBuf;
exports.testSamples = testSamples;
exports.testInflate = testInflate;
exports.loadSamples = loadSamples;

View file

@ -1,6 +1,3 @@
/*global describe, it*/
'use strict';
@ -168,7 +165,7 @@ describe('Inflate RAW', function () {
describe('Inflate with dictionary', function () {
it('should throw on the wrong dictionary', function () {
// var zCompressed = helpers.deflateSync('world', { dictionary: b('hello') });
// var zCompressed = helpers.deflateSync('world', { dictionary: Buffer.from('hello') });
var zCompressed = new Uint8Array([ 120, 187, 6, 44, 2, 21, 43, 207, 47, 202, 73, 1, 0, 6, 166, 2, 41 ]);
assert.throws(function () {

View file

@ -1,8 +1,4 @@
// This tests are ported from original zlib
/*global describe, it*/
'use strict';
@ -33,7 +29,7 @@ function testInflate(hex, wbits, status) {
return;
}
inflator.push(new Uint8Array(h2b(hex)), true);
assert.equal(inflator.err, status);
assert.strictEqual(inflator.err, status);
}

View file

@ -1,6 +1,3 @@
/*global describe, it*/
'use strict';
@ -9,7 +6,6 @@ var path = require('path');
var assert = require('assert');
var pako = require('../index');
var cmp = require('./helpers').cmpBuf;
describe('ArrayBuffer', function () {
@ -18,10 +14,10 @@ describe('ArrayBuffer', function () {
var deflated = pako.deflate(sample);
it('Deflate ArrayBuffer', function () {
assert.ok(cmp(deflated, pako.deflate(sample.buffer)));
assert.deepStrictEqual(deflated, pako.deflate(sample.buffer));
});
it('Inflate ArrayBuffer', function () {
assert.ok(cmp(sample, pako.inflate(deflated.buffer)));
assert.deepStrictEqual(sample, pako.inflate(deflated.buffer));
});
});

View file

@ -1,16 +1,11 @@
/*global describe, it*/
'use strict';
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var b = require('buffer-from');
var pako = require('../index');
var cmp = require('./helpers').cmpBuf;
var strings = require('../lib/utils/strings');
// fromCharCode, but understands right > 0xffff values
@ -43,43 +38,43 @@ describe('Encode/Decode', function () {
// Create sample, that contains all types of utf8 (1-4byte) after conversion
var utf16sample = a2utf16([ 0x1f3b5, 'a', 0x266a, 0x35, 0xe800, 0x10ffff, 0x0fffff ]);
// use node Buffer internal conversion as "done right"
var utf8sample = new Uint8Array(b(utf16sample));
var utf8sample = new Uint8Array(Buffer.from(utf16sample));
it('utf-8 border detect', function () {
var ub = strings.utf8border;
assert.equal(ub(utf8sample, 1), 1);
assert.equal(ub(utf8sample, 2), 2);
assert.equal(ub(utf8sample, 3), 3);
assert.equal(ub(utf8sample, 4), 4);
assert.strictEqual(ub(utf8sample, 1), 1);
assert.strictEqual(ub(utf8sample, 2), 2);
assert.strictEqual(ub(utf8sample, 3), 3);
assert.strictEqual(ub(utf8sample, 4), 4);
assert.equal(ub(utf8sample, 5), 5);
assert.strictEqual(ub(utf8sample, 5), 5);
assert.equal(ub(utf8sample, 6), 5);
assert.equal(ub(utf8sample, 7), 5);
assert.equal(ub(utf8sample, 8), 8);
assert.strictEqual(ub(utf8sample, 6), 5);
assert.strictEqual(ub(utf8sample, 7), 5);
assert.strictEqual(ub(utf8sample, 8), 8);
assert.equal(ub(utf8sample, 9), 9);
assert.strictEqual(ub(utf8sample, 9), 9);
assert.equal(ub(utf8sample, 10), 9);
assert.equal(ub(utf8sample, 11), 9);
assert.equal(ub(utf8sample, 12), 12);
assert.strictEqual(ub(utf8sample, 10), 9);
assert.strictEqual(ub(utf8sample, 11), 9);
assert.strictEqual(ub(utf8sample, 12), 12);
assert.equal(ub(utf8sample, 13), 12);
assert.equal(ub(utf8sample, 14), 12);
assert.equal(ub(utf8sample, 15), 12);
assert.equal(ub(utf8sample, 16), 16);
assert.strictEqual(ub(utf8sample, 13), 12);
assert.strictEqual(ub(utf8sample, 14), 12);
assert.strictEqual(ub(utf8sample, 15), 12);
assert.strictEqual(ub(utf8sample, 16), 16);
assert.equal(ub(utf8sample, 17), 16);
assert.equal(ub(utf8sample, 18), 16);
assert.equal(ub(utf8sample, 19), 16);
assert.equal(ub(utf8sample, 20), 20);
assert.strictEqual(ub(utf8sample, 17), 16);
assert.strictEqual(ub(utf8sample, 18), 16);
assert.strictEqual(ub(utf8sample, 19), 16);
assert.strictEqual(ub(utf8sample, 20), 20);
});
it('Encode string to utf8 buf', function () {
assert.ok(cmp(
assert.deepStrictEqual(
strings.string2buf(utf16sample),
utf8sample
));
);
});
it('Decode utf8 buf to string', function () {
@ -96,18 +91,18 @@ describe('Deflate/Inflate strings', function () {
var sampleArray = new Uint8Array(fs.readFileSync(file));
it('Deflate javascript string (utf16) on input', function () {
assert.ok(cmp(
assert.deepStrictEqual(
pako.deflate(sampleString),
pako.deflate(sampleArray)
));
);
});
it('Inflate with javascript string (utf16) output', function () {
var deflatedArray = pako.deflate(sampleArray);
var data = pako.inflate(deflatedArray, { to: 'string', chunkSize: 99 });
assert.equal(typeof data, 'string');
assert.equal(data, sampleString);
assert.strictEqual(typeof data, 'string');
assert.strictEqual(data, sampleString);
});
});