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') {
|
} else if (typeof buf === 'number') {
|
||||||
var num = buf;
|
var num = buf;
|
||||||
this.fromNumber(num);
|
this.fromNumber(num);
|
||||||
|
} else if (buf instanceof BN) {
|
||||||
|
var bn = buf;
|
||||||
|
this.fromBN(bn);
|
||||||
} else if (buf) {
|
} else if (buf) {
|
||||||
var obj = buf;
|
var obj = buf;
|
||||||
this.set(obj);
|
this.set(obj);
|
||||||
|
|
|
@ -14,6 +14,11 @@ describe('Varint', function() {
|
||||||
varint = Varint(buf);
|
varint = Varint(buf);
|
||||||
should.exist(varint);
|
should.exist(varint);
|
||||||
varint.buf.toString('hex').should.equal('00');
|
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() {
|
describe('#set', function() {
|
||||||
|
|
Loading…
Reference in New Issue