readVarInt -> readVarIntNum

"varInt" refers to the varInt object, which is not actually implemented yet.
This function should therefore really be called readVarIntNum.
This commit is contained in:
Ryan X. Charles 2014-09-15 14:19:08 -07:00
parent 8e959426e2
commit 3c668c9cf0
2 changed files with 7 additions and 7 deletions

View File

@ -79,7 +79,7 @@ BufferReader.prototype.readUInt64LEBN = function() {
return bn;
};
BufferReader.prototype.readVarInt = function() {
BufferReader.prototype.readVarIntNum = function() {
var first = this.readUInt8();
switch (first) {
case 0xFD:

View File

@ -168,32 +168,32 @@ describe('BufferReader', function() {
});
describe('#readVarInt', function() {
describe('#readVarIntNum', function() {
it('should read a 1 byte varint', function() {
var buf = new Buffer([50]);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(50);
br.readVarIntNum().should.equal(50);
});
it('should read a 3 byte varint', function() {
var buf = new Buffer([253, 253, 0]);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(253);
br.readVarIntNum().should.equal(253);
});
it('should read a 5 byte varint', function() {
var buf = new Buffer([254, 0, 0, 0, 0]);
buf.writeUInt32LE(50000, 1);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(50000);
br.readVarIntNum().should.equal(50000);
});
it('should throw an error on a 9 byte varint over the javascript uint precision limit', function() {
var buf = BufferWriter().writeVarIntBN(BN(Math.pow(2, 54).toString())).concat();
var br = new BufferReader({buf: buf});
(function() {
br.readVarInt();
br.readVarIntNum();
}).should.throw('number too large to retain precision - use readVarIntBN');
});
@ -201,7 +201,7 @@ describe('BufferReader', function() {
var buf = BufferWriter().writeVarIntBN(BN(Math.pow(2, 53).toString())).concat();
var br = new BufferReader({buf: buf});
(function() {
br.readVarInt();
br.readVarIntNum();
}).should.not.throw('number too large to retain precision - use readVarIntBN');
});