[issue249] fixed Buffer prototype & tests
This commit is contained in:
parent
eb79a956ea
commit
77e0ee7117
|
@ -9,6 +9,11 @@ function FilerBuffer (subject, encoding, nonZero) {
|
|||
return new Buffer(subject, encoding, nonZero);
|
||||
};
|
||||
|
||||
// Inherit prototype from Buffer
|
||||
FilerBuffer.prototype = Object.create(Buffer.prototype);
|
||||
FilerBuffer.prototype.constructor = FilerBuffer;
|
||||
|
||||
// Also copy static methods onto FilerBuffer ctor
|
||||
Object.keys(Buffer).forEach(function (p) {
|
||||
if (Buffer.hasOwnProperty(p)) {
|
||||
FilerBuffer[p] = Buffer[p];
|
||||
|
|
|
@ -12,3 +12,31 @@ describe('Filer.Buffer should accept initialized ArrayBuffers, issue 249', funct
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Filer.Buffer static methods are in tact, issue 249', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should proxy Buffer.isBuffer', function(done) {
|
||||
expect(Filer.Buffer.isBuffer(new Filer.Buffer([]))).to.equal(true);
|
||||
expect(Filer.Buffer.isBuffer('')).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should proxy Buffer.isEncoding', function(done) {
|
||||
expect(Filer.Buffer.isEncoding('utf8')).to.equal(true);
|
||||
expect(Filer.Buffer.isEncoding('smoop')).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should proxy Buffer.byteLength', function(done) {
|
||||
expect(Filer.Buffer.byteLength('01100111', 'binary')).to.equal(8);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should proxy Buffer.concat', function(done) {
|
||||
expect(Filer.Buffer.concat([new Filer.Buffer(1), new Filer.Buffer(2)]).length).to.equal(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue