Skip to content

Commit

Permalink
test: add tests for JSON5 stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
nechaido committed Jun 27, 2017
1 parent 133198c commit 1c088f7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/fixtures/serde-test-cases/serialization/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

module.exports = [].concat(
require('./number'),
require('./string'),
require('./array'),
require('./object')
);
19 changes: 19 additions & 0 deletions test/fixtures/serde-test-cases/serialization/number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = [
{
name: 'NaN',
value: NaN,
serialized: 'NaN'
},
{
name: 'Infinity',
value: Infinity,
serialized: 'Infinity'
},
{
name: '-Infinity',
value: -Infinity,
serialized: '-Infinity'
}
];
5 changes: 5 additions & 0 deletions test/fixtures/serde-test-cases/serialization/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ module.exports = [
name: 'object with non-identifier keys',
value: { '*': 42 },
serialized: '{\'*\':42}'
},
{
name: 'object with keyword as key',
value: { while: true },
serialized: '{while:true}'
}
];
19 changes: 19 additions & 0 deletions test/fixtures/serde-test-cases/serialization/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = [
{
name: 'string containing inline comment',
value: '// inline comment',
serialized: '\'// inline comment\''
},
{
name: 'string containing block comment',
value: '/* block comment */',
serialized: '\'/* block comment */\''
},
{
name: 'string with number inside',
value: '0.5',
serialized: '\'0.5\''
}
];
5 changes: 5 additions & 0 deletions test/fixtures/todo/serde/serialization/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = [].concat(
require('./object')
);
20 changes: 20 additions & 0 deletions test/fixtures/todo/serde/serialization/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

module.exports = [
{
name: 'object with numeric literal as key',
value: { 42: true },
serialized: '{42:true}'
},
{
name: 'object with identifier names as keys',
value: { $: 'dollar', _$_: 'multiple symbols' },
serialized: '{$:\'dollar\',_$_:\'multiple symbols\'}'
},
{
name: 'object with identifier name, ' +
'containing non-latin Unicode literals, as a key',
value: { ümlåût: 'that\'s not really an ümlaüt, but this is' },
serialized: '{ümlåût: \'that\\\'s not really an ümlaüt, but this is\'}'
}
];
13 changes: 13 additions & 0 deletions test/todo/serde.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const jstp = require('../..');

const test = require('tap').test;
const testCases = require('../fixtures/todo/serde/serialization');

testCases.forEach((testCase) => {
test(`must serialize ${testCase.name}`, (test) => {
test.strictSame(jstp.stringify(testCase.value), testCase.serialized);
test.end();
});
});

0 comments on commit 1c088f7

Please sign in to comment.