UNPKG

926 BJavaScriptView Raw
1
2var test = require('tape')
3var _JSON = require('../')
4
5function toJSON (o) {
6 return JSON.parse(JSON.stringify(o))
7}
8
9var examples = {
10 simple: { foo: [], bar: {}, baz: new Buffer('some binary data') },
11 just_buffer: new Buffer('JUST A BUFFER'),
12 all_types: {
13 string:'hello',
14 number: 3145,
15 null: null,
16 object: {},
17 array: [],
18 boolean: true,
19 boolean2: false
20 },
21 foo: new Buffer('foo'),
22 foo2: new Buffer('foo2'),
23 escape: {
24 buffer: new Buffer('x'),
25 string: _JSON.stringify(new Buffer('x'))
26 },
27 escape2: {
28 buffer: new Buffer('x'),
29 string: ':base64:'+ new Buffer('x').toString('base64')
30 },
31 undefined: {
32 empty: undefined
33 }
34}
35
36for(k in examples)
37(function (value, k) {
38 test(k, function (t) {
39 var s = _JSON.stringify(value)
40 console.log(s)
41 var _value = _JSON.parse(s)
42 t.deepEqual(toJSON(_value), toJSON(value))
43 t.end()
44 })
45})(examples[k], k)
46