3 var test = require('tape');
4 var stringify = require('../');
6 test('nested', function (t) {
8 var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
9 t.equal(stringify(obj), '{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}');
12 test('cyclic (default)', function (t) {
15 var two = { a: 2, one: one };
20 t.equal(ex.toString(), 'TypeError: Converting circular structure to JSON');
24 test('cyclic (specifically allowed)', function (t) {
27 var two = { a: 2, one: one };
29 t.equal(stringify(one, {cycles:true}), '{"a":1,"two":{"a":2,"one":"__cycle__"}}');
32 test('repeated non-cyclic value', function(t) {
35 var two = { a: one, b: one };
36 t.equal(stringify(two), '{"a":{"x":1},"b":{"x":1}}');
39 test('acyclic but with reused obj-property pointers', function (t) {
42 var y = { b: x, c: x };
43 t.equal(stringify(y), '{"b":{"a":1},"c":{"a":1}}');