Varint(BN()) convenience

...and add some tests for the various constructor conveniences
This commit is contained in:
Ryan X. Charles 2014-09-23 22:19:01 -07:00
parent 8e85eba08b
commit f54edfb618
2 changed files with 8 additions and 0 deletions

View File

@ -10,6 +10,9 @@ var Varint = function Varint(buf) {
} else if (typeof buf === 'number') {
var num = buf;
this.fromNumber(num);
} else if (buf instanceof BN) {
var bn = buf;
this.fromBN(bn);
} else if (buf) {
var obj = buf;
this.set(obj);

View File

@ -14,6 +14,11 @@ describe('Varint', function() {
varint = Varint(buf);
should.exist(varint);
varint.buf.toString('hex').should.equal('00');
//various ways to use the constructor
Varint(Varint(0).toBuffer()).toNumber().should.equal(0);
Varint(0).toNumber().should.equal(0);
Varint(BN(0)).toNumber().should.equal(0);
});
describe('#set', function() {