Skip to content

Commit

Permalink
devDependencies: msgpack-test-js
Browse files Browse the repository at this point in the history
(cherry picked from commit d9fc4c6)
  • Loading branch information
kawanet authored and p2k committed Jun 13, 2023
1 parent fe038f5 commit 7133f9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"concat-stream": "^1.5.2",
"jshint": "^2.9.3",
"mocha": "^3.1.2",
"msgpack.codec": "git+https://github.com/kawanet/msgpack-javascript.git#msgpack.codec",
"msgpack-test-js": "git+https://github.com/kawanet/msgpack-test-js.git",
"uglify-js": "^2.7.3"
},
"homepage": "https://github.com/meetnow/msgpack-long-lite",
Expand Down
52 changes: 23 additions & 29 deletions test/50.msgpack-test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require("assert");
var msgpackJS = "../index";
var isBrowser = ("undefined" !== typeof window);
var msgpack = isBrowser && window.msgpack || require(msgpackJS);
var Suite = require("msgpack-test-js").Suite;
var Exam = require("msgpack-test-js").Exam;

var TITLE = __filename.split("/").pop();

Expand All @@ -27,34 +27,28 @@ var opt = {codec: msgpack.createCodec({int64: true})};
*/

describe(TITLE, function() {
var suite = new Suite();

// get an array of groups
suite.getGroups().forEach(function(group) {

// get an array of exams
suite.getExams(group).forEach(function(exam) {
var types = exam.getTypes(TEST_TYPES);

// skip when types not supported
if (!types.length) return;

var title = types[0] + ": " + exam.stringify(types[0]);
it(title, function() {

// test for encoding
types.forEach(function(type) {
var value = exam.getValue(type);
var buffer = msgpack.encode(value, opt);
assert(exam.matchMsgpack(buffer), exam.stringify(type));
});

// test for decoding
var msgpacks = exam.getMsgpacks();
msgpacks.forEach(function(encoded, idx) {
var value = msgpack.decode(encoded, opt);
assert(exam.matchValue(value), exam.stringify(idx));
});

// find exams for types supported by the library
Exam.getExams(TEST_TYPES).forEach(function(exam) {

// find types tested by the exam
var types = exam.getTypes(TEST_TYPES);
var first = types[0];
var title = first + ": " + exam.stringify(first);
it(title, function() {

// test for encoding
types.forEach(function(type) {
var value = exam.getValue(type);
var buffer = msgpack.encode(value, opt);
assert(exam.matchMsgpack(buffer), exam.stringify(type));
});

// test for decoding
var msgpacks = exam.getMsgpacks();
msgpacks.forEach(function(encoded, idx) {
var value = msgpack.decode(encoded, opt);
assert(exam.matchValue(value), exam.stringify(idx));
});
});
});
Expand Down

0 comments on commit 7133f9c

Please sign in to comment.