[test] Add tests

This commit is contained in:
Luigi Pinca
2017-03-03 11:08:29 +01:00
parent 159df5ef6b
commit 92e1b258ec
3 changed files with 50 additions and 1 deletions
+1
View File
@@ -1,4 +1,5 @@
prebuilds/
build/
appveyor.yml
test.js
.*
+2 -1
View File
@@ -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"
}
+47
View File
@@ -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')));