source: imaps-frontend/node_modules/json-buffer/test/index.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1
2var test = require('tape')
3var _JSON = require('../')
4
5function clone (o) {
6 return JSON.parse(JSON.stringify(o))
7}
8
9var examples = {
10 simple: { foo: [], bar: {}, baz: Buffer.from('some binary data') },
11 just_buffer: Buffer.from('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: Buffer.from('foo'),
22 foo2: Buffer.from('foo2'),
23 escape: {
24 buffer: Buffer.from('x'),
25 string: _JSON.stringify(Buffer.from('x'))
26 },
27 escape2: {
28 buffer: Buffer.from('x'),
29 string: ':base64:'+ Buffer.from('x').toString('base64')
30 },
31 undefined: {
32 empty: undefined, test: true
33 },
34 undefined2: {
35 first: 1, empty: undefined, test: true
36 },
37 undefinedArray: {
38 array: [undefined, 1, 'two']
39 },
40 fn: {
41 fn: function () {}
42 },
43 undefined: undefined
44}
45
46for(k in examples)
47(function (value, k) {
48 test(k, function (t) {
49 var s = _JSON.stringify(value)
50 console.log('parse', s)
51 if(JSON.stringify(value) !== undefined) {
52 console.log(s)
53 var _value = _JSON.parse(s)
54 t.deepEqual(clone(_value), clone(value))
55 }
56 else
57 t.equal(s, undefined)
58 t.end()
59 })
60})(examples[k], k)
61
62
63
Note: See TracBrowser for help on using the repository browser.