Skip to content

Commit

Permalink
Fixed full encode/decode of -32 and updated unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Trimble committed May 21, 2015
1 parent 10a6b69 commit c61e6e6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = function buildEncode(encodingTypes) {
write64BitUint(buf, obj)
}
} else {
if (obj > -32) {
if (obj >= -32) {
buf = new Buffer(1)
buf[0] = 0x100 + obj
} else if (obj >= -128) {
Expand Down
14 changes: 1 addition & 13 deletions test/5-bits-negative-integers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@ test('encoding/decoding 5-bits negative ints', function(t) {
, allNum = []
, i

for (i = 1; i < 32; i++) {
for (i = 1; i <= 32; i++) {
allNum.push(-i)
}

t.test('encoding negative 32', function(t) {
var buf = encoder.encode(-0)
t.equal(buf.length, 1, 'must have 1 byte')
t.equal(buf[0], 0x0, 'must encode correctly')
t.end()
})
t.test('decoding negative 32', function(t) {
var buf = encoder.decode(new Buffer([0xe0]))
t.equal(buf, -32, 'must decode correctly')
t.end()
})

allNum.forEach(function(num) {
t.test('encoding ' + num, function(t) {
var buf = encoder.encode(num)
Expand Down
2 changes: 1 addition & 1 deletion test/8-bits-signed-integers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('encoding/decoding 8-bits big-endian signed integers', function(t) {
, allNum = []
, i

for (i = 32; i <= 128; i++) {
for (i = 33; i <= 128; i++) {
allNum.push(-i)
}

Expand Down

0 comments on commit c61e6e6

Please sign in to comment.