Browse Source

Varint(BN()) convenience

...and add some tests for the various constructor conveniences
patch-2
Ryan X. Charles 10 years ago
parent
commit
f54edfb618
  1. 3
      lib/varint.js
  2. 5
      test/varint.js

3
lib/varint.js

@ -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);

5
test/varint.js

@ -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…
Cancel
Save