]> git.r.bdr.sh - rbdr/dotfiles/blame - atom/packages/pretty-json/node_modules/json-stable-stringify/test/nested.js
Remove vim-surround
[rbdr/dotfiles] / atom / packages / pretty-json / node_modules / json-stable-stringify / test / nested.js
CommitLineData
06a3d686
BB
1var test = require('tape');
2var stringify = require('../');
3
4test('nested', function (t) {
5 t.plan(1);
6 var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
7 t.equal(stringify(obj), '{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}');
8});
9
10test('cyclic (default)', function (t) {
11 t.plan(1);
12 var one = { a: 1 };
13 var two = { a: 2, one: one };
14 one.two = two;
15 try {
16 stringify(one);
17 } catch (ex) {
18 t.equal(ex.toString(), 'TypeError: Converting circular structure to JSON');
19 }
20});
21
22test('cyclic (specifically allowed)', function (t) {
23 t.plan(1);
24 var one = { a: 1 };
25 var two = { a: 2, one: one };
26 one.two = two;
27 t.equal(stringify(one, {cycles:true}), '{"a":1,"two":{"a":2,"one":"__cycle__"}}');
28});