1 | #!/usr/bin/env mocha -R spec
|
2 |
|
3 | var assert = require("assert");
|
4 |
|
5 | var msgpack = require("../index");
|
6 | var TITLE = __filename.replace(/^.*\//, "") + ":";
|
7 |
|
8 | var data = require("./example.json");
|
9 |
|
10 | describe(TITLE, function() {
|
11 | test("msgpack", function(they) {
|
12 | assert.deepEqual(they.unpack(msgpack.encode(data)), data);
|
13 | assert.deepEqual(msgpack.decode(Buffer(they.pack(data))), data);
|
14 | });
|
15 |
|
16 | test("msgpack-js", function(they) {
|
17 | assert.deepEqual(they.decode(msgpack.encode(data)), data);
|
18 | assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
|
19 | });
|
20 |
|
21 | test("msgpack-js-v5", function(they) {
|
22 | assert.deepEqual(they.decode(msgpack.encode(data)), data);
|
23 | assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
|
24 | });
|
25 |
|
26 | test("msgpack5", function(they) {
|
27 | they = they();
|
28 | assert.deepEqual(they.decode(msgpack.encode(data)), data);
|
29 | assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
|
30 | });
|
31 |
|
32 | test("msgpack-unpack", function(they) {
|
33 | assert.deepEqual(they(msgpack.encode(data)), data);
|
34 | });
|
35 |
|
36 | test("msgpack-javascript", function(they) {
|
37 | they = they.msgpack;
|
38 | assert.deepEqual(they.unpack(msgpack.encode(data)), data);
|
39 | assert.deepEqual(msgpack.decode(Buffer(they.pack(data))), data);
|
40 | });
|
41 | });
|
42 |
|
43 | function test(name, func) {
|
44 | var they;
|
45 | var method = it;
|
46 | try {
|
47 | they = require(name);
|
48 | } catch (e) {
|
49 | method = it.skip;
|
50 | name += ": " + e;
|
51 | }
|
52 | method(name, func.bind(null, they));
|
53 | }
|