source: node_modules/json-stable-stringify/test/space.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var test = require('tape');
4var stringify = require('../');
5
6test('space parameter', function (t) {
7 t.plan(1);
8 var obj = { one: 1, two: 2 };
9 t.equal(
10 stringify(obj, { space: ' ' }),
11 ''
12 + '{\n'
13 + ' "one": 1,\n'
14 + ' "two": 2\n'
15 + '}'
16 );
17});
18
19test('space parameter (with tabs)', function (t) {
20 t.plan(1);
21 var obj = { one: 1, two: 2 };
22 t.equal(
23 stringify(obj, { space: '\t' }),
24 ''
25 + '{\n'
26 + '\t"one": 1,\n'
27 + '\t"two": 2\n'
28 + '}'
29 );
30});
31
32test('space parameter (with a number)', function (t) {
33 t.plan(1);
34 var obj = { one: 1, two: 2 };
35 t.equal(
36 stringify(obj, { space: 3 }),
37 ''
38 + '{\n'
39 + ' "one": 1,\n'
40 + ' "two": 2\n'
41 + '}'
42 );
43});
44
45test('space parameter (nested objects)', function (t) {
46 t.plan(1);
47 var obj = { one: 1, two: { b: 4, a: [2, 3] } };
48 t.equal(
49 stringify(obj, { space: ' ' }),
50 ''
51 + '{\n'
52 + ' "one": 1,\n'
53 + ' "two": {\n'
54 + ' "a": [\n'
55 + ' 2,\n'
56 + ' 3\n'
57 + ' ],\n'
58 + ' "b": 4\n'
59 + ' }\n'
60 + '}'
61 );
62});
63
64test('space parameter (same as native)', function (t) {
65 t.plan(1);
66 // for this test, properties need to be in alphabetical order
67 var obj = { one: 1, two: { a: [2, 3], b: 4 } };
68 t.equal(
69 stringify(obj, { space: ' ' }),
70 JSON.stringify(obj, null, ' ')
71 );
72});
Note: See TracBrowser for help on using the repository browser.