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 undefined as first property value', function (t) {
|
---|
19 | t.plan(1);
|
---|
20 | var obj = { a: undefined, z: 3};
|
---|
21 | t.equal(stringify(obj), '{"z":3}');
|
---|
22 | });
|
---|
23 |
|
---|
24 | test('object with null', function (t) {
|
---|
25 | t.plan(1);
|
---|
26 | var obj = { a: 3, z: null };
|
---|
27 | t.equal(stringify(obj), '{"a":3,"z":null}');
|
---|
28 | });
|
---|
29 |
|
---|
30 | test('object with NaN and Infinity', function (t) {
|
---|
31 | t.plan(1);
|
---|
32 | var obj = { a: 3, b: NaN, c: Infinity };
|
---|
33 | t.equal(stringify(obj), '{"a":3,"b":null,"c":null}');
|
---|
34 | });
|
---|
35 |
|
---|
36 | test('array with undefined', function (t) {
|
---|
37 | t.plan(1);
|
---|
38 | var obj = [4, undefined, 6];
|
---|
39 | t.equal(stringify(obj), '[4,null,6]');
|
---|
40 | });
|
---|
41 |
|
---|
42 | test('object with empty string', function (t) {
|
---|
43 | t.plan(1);
|
---|
44 | var obj = { a: 3, z: '' };
|
---|
45 | t.equal(stringify(obj), '{"a":3,"z":""}');
|
---|
46 | });
|
---|
47 |
|
---|
48 | test('array with empty string', function (t) {
|
---|
49 | t.plan(1);
|
---|
50 | var obj = [4, '', 6];
|
---|
51 | t.equal(stringify(obj), '[4,"",6]');
|
---|
52 | });
|
---|