forked from mcollina/msgpack5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support and test for map32 - a map with items of up to length 2^32-1 A few tests were added to check that the support is working as expected. Fixes mcollina#54
- Loading branch information
1 parent
005eceb
commit 2dc73e4
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict' | ||
|
||
var test = require('tape').test | ||
var msgpack = require('../') | ||
|
||
test('encode/decode map with 10 keys', function (t) { | ||
var map = {} | ||
|
||
for (var i = 0; i < 10; i++) { | ||
map[i] = i | ||
} | ||
|
||
var pack = msgpack() | ||
|
||
var encoded = pack.encode(map) | ||
|
||
// map16 byte | ||
t.equal(encoded[0], 0x8A) | ||
|
||
t.deepEqual(pack.decode(encoded), map) | ||
t.end() | ||
}) | ||
|
||
test('encode/decode map with 10000 keys', function (t) { | ||
var map = {} | ||
|
||
for (var i = 0; i < 10000; i++) { | ||
map[i] = i | ||
} | ||
|
||
var pack = msgpack() | ||
|
||
var encoded = pack.encode(map) | ||
|
||
// map16 byte | ||
t.equal(encoded[0], 0xde) | ||
|
||
t.deepEqual(pack.decode(encoded), map) | ||
t.end() | ||
}) | ||
|
||
test('encode/decode map with 100000 keys', function (t) { | ||
var map = {} | ||
|
||
for (var i = 0; i < 100000; i++) { | ||
map[i] = i | ||
} | ||
|
||
var pack = msgpack() | ||
|
||
var encoded = pack.encode(map) | ||
|
||
// map32 byte | ||
t.equal(encoded[0], 0xdf) | ||
|
||
t.deepEqual(pack.decode(encoded), map) | ||
t.end() | ||
}) | ||
|
||
test('encode/decode map with 1000000 keys', function (t) { | ||
var map = {} | ||
|
||
for (var i = 0; i < 1000000; i++) { | ||
map[i] = i | ||
} | ||
|
||
var pack = msgpack() | ||
|
||
t.deepEqual(pack.decode(pack.encode(map)), map) | ||
t.end() | ||
}) |