Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | var test = require('tape'); |
| 4 | var stringify = require('../'); |
| 5 | |
| 6 | test('simple object', function (t) { |
| 7 | t.plan(1); |
| 8 | var obj = { c: 6, b: [4,5], a: 3, z: null }; |
| 9 | t.equal(stringify(obj), '{"a":3,"b":[4,5],"c":6,"z":null}'); |
| 10 | }); |
| 11 | |
| 12 | test('object with undefined', function (t) { |
| 13 | t.plan(1); |
| 14 | var obj = { a: 3, z: undefined }; |
| 15 | t.equal(stringify(obj), '{"a":3}'); |
| 16 | }); |
| 17 | |
| 18 | test('object with null', function (t) { |
| 19 | t.plan(1); |
| 20 | var obj = { a: 3, z: null }; |
| 21 | t.equal(stringify(obj), '{"a":3,"z":null}'); |
| 22 | }); |
| 23 | |
| 24 | test('object with NaN and Infinity', function (t) { |
| 25 | t.plan(1); |
| 26 | var obj = { a: 3, b: NaN, c: Infinity }; |
| 27 | t.equal(stringify(obj), '{"a":3,"b":null,"c":null}'); |
| 28 | }); |
| 29 | |
| 30 | test('array with undefined', function (t) { |
| 31 | t.plan(1); |
| 32 | var obj = [4, undefined, 6]; |
| 33 | t.equal(stringify(obj), '[4,null,6]'); |
| 34 | }); |
| 35 | |
| 36 | test('object with empty string', function (t) { |
| 37 | t.plan(1); |
| 38 | var obj = { a: 3, z: '' }; |
| 39 | t.equal(stringify(obj), '{"a":3,"z":""}'); |
| 40 | }); |
| 41 | |
| 42 | test('array with empty string', function (t) { |
| 43 | t.plan(1); |
| 44 | var obj = [4, '', 6]; |
| 45 | t.equal(stringify(obj), '[4,"",6]'); |
| 46 | }); |