mirror of
https://github.com/hanzoai/bufferutil.git
synced 2026-09-24 16:57:30 +00:00
[test] Add tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
prebuilds/
|
||||
build/
|
||||
appveyor.yml
|
||||
test.js
|
||||
.*
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"install": "prebuild-install || node-gyp rebuild",
|
||||
"test": "echo \"Only testing builds, tests have to be extraced from ws\" && prebuild-ci"
|
||||
"test": "mocha && prebuild-ci"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -26,6 +26,7 @@
|
||||
"prebuild-install": "~2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~3.2.0",
|
||||
"prebuild": "~6.1.0",
|
||||
"prebuild-ci": "~2.2.0"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
function use(bufferUtil) {
|
||||
return function () {
|
||||
it('masks a buffer (1/2)', function () {
|
||||
const buf = Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f]);
|
||||
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
|
||||
|
||||
bufferUtil.mask(buf, mask, buf, 0, buf.length);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
buf,
|
||||
Buffer.from([0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb])
|
||||
);
|
||||
});
|
||||
|
||||
it('masks a buffer (2/2)', function () {
|
||||
const src = Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f]);
|
||||
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
|
||||
const dest = Buffer.alloc(src.length + 2);
|
||||
|
||||
bufferUtil.mask(src, mask, dest, 2, src.length);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
dest,
|
||||
Buffer.from([0x00, 0x00, 0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb])
|
||||
);
|
||||
});
|
||||
|
||||
it('unmasks a buffer', function () {
|
||||
const buf = Buffer.from([0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb]);
|
||||
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
|
||||
|
||||
bufferUtil.unmask(buf, mask);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
buf,
|
||||
Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f])
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
describe('bindings', use(require('bindings')('bufferutil')));
|
||||
describe('fallback', use(require('./fallback')));
|
||||
Reference in New Issue
Block a user