Blame view

node_modules/msgpack5/test/5-bits-negative-integers.js 826 Bytes
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  'use strict'
  
  var test = require('tape').test
  var msgpack = require('../')
  
  test('encoding/decoding 5-bits negative ints', function (t) {
    var encoder = msgpack()
    var allNum = []
  
    for (var i = 1; i <= 32; i++) {
      allNum.push(-i)
    }
  
    allNum.forEach(function (num) {
      t.test('encoding ' + num, function (t) {
        var buf = encoder.encode(num)
        t.equal(buf.length, 1, 'must have 1 byte')
        t.equal(buf[0], num + 0x100, 'must encode correctly')
        t.end()
      })
  
      t.test('decoding' + num, function (t) {
        var buf = new Buffer([num + 0x100])
        t.equal(encoder.decode(buf), num, 'must decode correctly')
        t.end()
      })
  
      t.test('mirror test' + num, function (t) {
        t.equal(encoder.decode(encoder.encode(num)), num, 'must stay the same')
        t.end()
      })
    })
  
    t.end()
  })