Varint(BN()) convenience
...and add some tests for the various constructor conveniences
This commit is contained in:
parent
8e85eba08b
commit
f54edfb618
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue