basant307/AI_Governance_Project
048
1'use strict';2 3var test = require('tape');4var stringify = require('../');5 6test('nested', function (t) {7 t.plan(1);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}');10});11 12test('cyclic (default)', function (t) {13 t.plan(1);14 var one = { a: 1, two: {} };15 var two = { a: 2, one: one };16 one.two = two;17 try {18 stringify(one);19 } catch (ex) {20 if (ex == null) { // eslint-disable-line eqeqeq21 t.fail('nullish exception');22 } else {23 t.equal(ex.toString(), 'TypeError: Converting circular structure to JSON');24 }25 }26});27 28test('cyclic (specifically allowed)', function (t) {29 t.plan(1);30 var one = { a: 1, two: {} };31 var two = { a: 2, one: one };32 one.two = two;33 t.equal(stringify(one, { cycles: true }), '{"a":1,"two":{"a":2,"one":"__cycle__"}}');34});35 36test('repeated non-cyclic value', function (t) {37 t.plan(1);38 var one = { x: 1 };39 var two = { a: one, b: one };40 t.equal(stringify(two), '{"a":{"x":1},"b":{"x":1}}');41});42 43test('acyclic but with reused obj-property pointers', function (t) {44 t.plan(1);45 var x = { a: 1 };46 var y = { b: x, c: x };47 t.equal(stringify(y), '{"b":{"a":1},"c":{"a":1}}');48});49 