]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/json-stable-stringify/test/space.js
Update atoms
[rbdr/dotfiles] / atom / packages / pretty-json / node_modules / json-stable-stringify / test / space.js
1 var test = require('tape');
2 var stringify = require('../');
3
4 test('space parameter', function (t) {
5 t.plan(1);
6 var obj = { one: 1, two: 2 };
7 t.equal(stringify(obj, {space: ' '}), ''
8 + '{\n'
9 + ' "one": 1,\n'
10 + ' "two": 2\n'
11 + '}'
12 );
13 });
14
15 test('space parameter (with tabs)', function (t) {
16 t.plan(1);
17 var obj = { one: 1, two: 2 };
18 t.equal(stringify(obj, {space: '\t'}), ''
19 + '{\n'
20 + '\t"one": 1,\n'
21 + '\t"two": 2\n'
22 + '}'
23 );
24 });
25
26 test('space parameter (with a number)', function (t) {
27 t.plan(1);
28 var obj = { one: 1, two: 2 };
29 t.equal(stringify(obj, {space: 3}), ''
30 + '{\n'
31 + ' "one": 1,\n'
32 + ' "two": 2\n'
33 + '}'
34 );
35 });
36
37 test('space parameter (nested objects)', function (t) {
38 t.plan(1);
39 var obj = { one: 1, two: { b: 4, a: [2,3] } };
40 t.equal(stringify(obj, {space: ' '}), ''
41 + '{\n'
42 + ' "one": 1,\n'
43 + ' "two": {\n'
44 + ' "a": [\n'
45 + ' 2,\n'
46 + ' 3\n'
47 + ' ],\n'
48 + ' "b": 4\n'
49 + ' }\n'
50 + '}'
51 );
52 });
53
54 test('space parameter (same as native)', function (t) {
55 t.plan(1);
56 // for this test, properties need to be in alphabetical order
57 var obj = { one: 1, two: { a: [2,3], b: 4 } };
58 t.equal(stringify(obj, {space: ' '}), JSON.stringify(obj, null, ' '));
59 });