]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/json-stable-stringify/test/nested.js
1 var test
= require('tape');
2 var stringify
= require('../');
4 test('nested', function (t
) {
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}');
10 test('cyclic (default)', function (t
) {
13 var two
= { a: 2, one: one
};
18 t
.equal(ex
.toString(), 'TypeError: Converting circular structure to JSON');
22 test('cyclic (specifically allowed)', function (t
) {
25 var two
= { a: 2, one: one
};
27 t
.equal(stringify(one
, {cycles:true}), '{"a":1,"two":{"a":2,"one":"__cycle__"}}');