MCPcopy Create free account
hub / github.com/WebReflection/JSONH / wru

Function wru

js/test/jsonh.js:2–125  ·  view source on GitHub ↗
(wru)

Source from the content-addressed store, hash-verified

1// https://github.com/WebReflection/wru
2function wru(wru){var assert=wru.assert,async=wru.async;
3
4var jsonh = require("../jsonh");
5
6// enojy your tests!
7wru.test([
8 {
9 name: "nested array and schema",
10 test: function () {
11 var
12 object = [{a:[[{b:12}]]}],
13 initial = JSON.stringify(object),
14 schema = ['a.c']
15 ;
16 assert("back to normal", initial === JSON.stringify(jsonh.parse(jsonh.stringify(object, null, null, schema), null, schema)));
17 }
18 }, {
19 name: "require did not fail",
20 test: function () {
21 assert("jsonh is an object", typeof jsonh == "object");
22 assert("jsonh.parse is a function", typeof jsonh.parse == "function");
23 assert("jsonh.stringify is a function", typeof jsonh.stringify == "function");
24 assert("jsonh.pack is a function", typeof jsonh.pack == "function");
25 assert("jsonh.unpack is a function", typeof jsonh.unpack == "function");
26 }
27 }, {
28 name: "un/packing without schema",
29 test: function () {
30 var
31 original = [{a:"A"},{a:"B"}],
32 soriginal = JSON.stringify(original),
33 packed = jsonh.pack(original),
34 spacked = JSON.stringify(packed)
35 ;
36 assert("successfully packed", spacked == '[1,"a","A","B"]');
37 assert("successfully unpacked", JSON.stringify(jsonh.unpack(packed)) == soriginal);
38 assert("successfully stringified", jsonh.stringify(JSON.parse(soriginal)) === spacked);
39 assert("successfully parsed", JSON.stringify(jsonh.parse(spacked)) == soriginal);
40 }
41 }, {
42 name: "un/packing with schema",
43 test: function () {
44 var
45 schema = ["b.c", "b.d"],
46 test = [
47 {
48 b: {
49 c: [
50 {a: 1},
51 {a: 2}
52 ],
53 d: [
54 {a: 3},
55 {a: 4}
56 ]
57 }
58 }, {
59 a: 1,
60 b: {

Callers 1

jsonh.jsFile · 0.85

Calls 4

stringifyMethod · 0.80
parseMethod · 0.80
packMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected