diff --git a/test/fixtures/serde-test-cases/serialization/index.js b/test/fixtures/serde-test-cases/serialization/index.js index 2f5fe16..af1183b 100644 --- a/test/fixtures/serde-test-cases/serialization/index.js +++ b/test/fixtures/serde-test-cases/serialization/index.js @@ -1,6 +1,8 @@ 'use strict'; module.exports = [].concat( + require('./number'), + require('./string'), require('./array'), require('./object') ); diff --git a/test/fixtures/serde-test-cases/serialization/number.js b/test/fixtures/serde-test-cases/serialization/number.js new file mode 100644 index 0000000..cffddec --- /dev/null +++ b/test/fixtures/serde-test-cases/serialization/number.js @@ -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' + } +]; diff --git a/test/fixtures/serde-test-cases/serialization/object.js b/test/fixtures/serde-test-cases/serialization/object.js index 7090dba..e31e3a8 100644 --- a/test/fixtures/serde-test-cases/serialization/object.js +++ b/test/fixtures/serde-test-cases/serialization/object.js @@ -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}' } ]; diff --git a/test/fixtures/serde-test-cases/serialization/string.js b/test/fixtures/serde-test-cases/serialization/string.js new file mode 100644 index 0000000..dbed90a --- /dev/null +++ b/test/fixtures/serde-test-cases/serialization/string.js @@ -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\'' + } +]; diff --git a/test/fixtures/todo/serde/serialization/index.js b/test/fixtures/todo/serde/serialization/index.js new file mode 100644 index 0000000..71a1034 --- /dev/null +++ b/test/fixtures/todo/serde/serialization/index.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = [].concat( + require('./object') +); diff --git a/test/fixtures/todo/serde/serialization/object.js b/test/fixtures/todo/serde/serialization/object.js new file mode 100644 index 0000000..a1a2dce --- /dev/null +++ b/test/fixtures/todo/serde/serialization/object.js @@ -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\'}' + } +]; diff --git a/test/todo/serde.js b/test/todo/serde.js new file mode 100644 index 0000000..e2c7637 --- /dev/null +++ b/test/todo/serde.js @@ -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(); + }); +});