mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-11 14:21:02 +01:00
tests cleanup
This commit is contained in:
parent
144a94e3f8
commit
373115b4e9
1 changed files with 20 additions and 44 deletions
|
@ -3,56 +3,32 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
var c = require('../lib/zlib/constants');
|
|
||||||
|
|
||||||
var pako_utils = require('../lib/zlib/utils');
|
var c = require('../lib/zlib/constants');
|
||||||
var pako_msg = require('../lib/zlib/messages');
|
|
||||||
var pako = require('../index');
|
var pako = require('../index');
|
||||||
|
|
||||||
|
|
||||||
function h2b(hex) {
|
function h2b(hex) {
|
||||||
var tmp = hex.split(' ');
|
return hex.split(' ').map(function(hex) { return parseInt(hex, 16); });
|
||||||
var res = new pako_utils.Buf8(tmp.length);
|
|
||||||
for (var i=0; i<tmp.length; i++) {
|
|
||||||
res[i] = parseInt(tmp[i], 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInflate(hex, wbits, err) {
|
function a2s(array) {
|
||||||
var inflator;
|
return String.fromCharCode.apply(null, array);
|
||||||
|
|
||||||
var assert_fn = err === c.Z_OK ? assert.doesNotThrow : assert.throws;
|
|
||||||
|
|
||||||
assert_fn(function() {
|
|
||||||
inflator = new pako.Inflate({windowBits: wbits});
|
|
||||||
inflator.push(h2b(hex), true);
|
|
||||||
if (inflator.err) {
|
|
||||||
throw new Error(inflator.err);
|
|
||||||
}
|
|
||||||
}, pako_msg[err]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInflateGzHeader(sample, field, expected) {
|
function testInflate(hex, wbits, status) {
|
||||||
var data, actual;
|
var inflator = new pako.Inflate({ windowBits: wbits });
|
||||||
data = new Uint8Array(fs.readFileSync(path.join(__dirname, 'fixtures/header', sample)));
|
inflator.push(h2b(hex), true);
|
||||||
|
assert.equal(inflator.err, status);
|
||||||
var inflator = new pako.Inflate();
|
|
||||||
inflator.push(data, true);
|
|
||||||
|
|
||||||
actual = inflator.header[field];
|
|
||||||
if (actual instanceof pako_utils.Buf8) {
|
|
||||||
actual = String.fromCharCode.apply(null, actual);
|
|
||||||
}
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
describe('Inflate coverage wrap', function() {
|
describe('Inflate states', function() {
|
||||||
it('bad gzip method', function() {
|
it('bad gzip method', function() {
|
||||||
testInflate('1f 8b 0 0', 31, c.Z_DATA_ERROR);
|
testInflate('1f 8b 0 0', 31, c.Z_DATA_ERROR);
|
||||||
});
|
});
|
||||||
|
@ -88,14 +64,14 @@ describe('Inflate coverage wrap', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Inflate coverage gzip header', function() {
|
describe('Inflate gzip header', function() {
|
||||||
it('check filename', function() {
|
it('Check headers content from prepared file', function() {
|
||||||
testInflateGzHeader('test.gz', 'name', 'test name');
|
var data = fs.readFileSync(path.join(__dirname, 'fixtures/header/test.gz'));
|
||||||
});
|
var inflator = new pako.Inflate();
|
||||||
it('check comment', function() {
|
inflator.push(data, true);
|
||||||
testInflateGzHeader('test.gz', 'comment', 'test comment');
|
|
||||||
});
|
assert.equal(inflator.header.name, 'test name');
|
||||||
it('check extra', function() {
|
assert.equal(inflator.header.comment, 'test comment');
|
||||||
testInflateGzHeader('test.gz', 'extra', 'test extra');
|
assert.equal(a2s(inflator.header.extra), 'test extra');
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Add table
Reference in a new issue