diff --git a/test/fixtures/serde-test-cases/deserialization.js b/test/fixtures/serde-test-cases/deserialization.js deleted file mode 100644 index a626cc5a..00000000 --- a/test/fixtures/serde-test-cases/deserialization.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -module.exports = [ - { - name: 'object with whitespaces', - value: { key: 42 }, - serialized: '{ key:\n\t42 }' - }, - { - name: 'object with single-quoted keys', - value: { key: 42 }, - serialized: '{\'key\': 42}' - }, - { - name: 'object with double-quoted keys', - value: { key: 42 }, - serialized: '{"key": 42}' - }, - { - name: 'binary numbers', - value: 10, - serialized: '0b1010' - }, - { - name: 'octal numbers', - value: 83, - serialized: '0o123' - }, - { - name: 'hexadecimal numbers', - value: 0xff, - serialized: '0xff' - }, - { - name: 'hexadecimal numbers in upper case', - value: 0xAF, - serialized: '0xAF' - }, - { - name: 'Unicode code point escapes', - value: '💚💛', - serialized: '\'\\u{1F49A}\\u{1F49B}\'' - }, - { - name: 'sparse array', - value: [1, undefined, 3], - serialized: '[1,,3]' - } -]; diff --git a/test/fixtures/serde-test-cases/deserialization/array.js b/test/fixtures/serde-test-cases/deserialization/array.js new file mode 100644 index 00000000..9713161f --- /dev/null +++ b/test/fixtures/serde-test-cases/deserialization/array.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = [ + { + name: 'sparse array', + value: [1, undefined, 3], + serialized: '[1,,3]' + } +]; diff --git a/test/fixtures/serde-test-cases/deserialization/index.js b/test/fixtures/serde-test-cases/deserialization/index.js new file mode 100644 index 00000000..af1183b7 --- /dev/null +++ b/test/fixtures/serde-test-cases/deserialization/index.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = [].concat( + require('./number'), + require('./string'), + require('./array'), + require('./object') +); diff --git a/test/fixtures/serde-test-cases/deserialization/number.js b/test/fixtures/serde-test-cases/deserialization/number.js new file mode 100644 index 00000000..c289052b --- /dev/null +++ b/test/fixtures/serde-test-cases/deserialization/number.js @@ -0,0 +1,24 @@ +'use strict'; + +module.exports = [ + { + name: 'binary numbers', + value: 10, + serialized: '0b1010' + }, + { + name: 'octal numbers', + value: 83, + serialized: '0o123' + }, + { + name: 'hexadecimal numbers', + value: 0xff, + serialized: '0xff' + }, + { + name: 'hexadecimal numbers in upper case', + value: 0xAF, + serialized: '0xAF' + } +]; diff --git a/test/fixtures/serde-test-cases/deserialization/object.js b/test/fixtures/serde-test-cases/deserialization/object.js new file mode 100644 index 00000000..74181750 --- /dev/null +++ b/test/fixtures/serde-test-cases/deserialization/object.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = [ + { + name: 'object with whitespaces', + value: { key: 42 }, + serialized: '{ key:\n\t42 }' + }, + { + name: 'object with single-quoted keys', + value: { key: 42 }, + serialized: '{\'key\': 42}' + }, + { + name: 'object with double-quoted keys', + value: { key: 42 }, + serialized: '{"key": 42}' + } +]; diff --git a/test/fixtures/serde-test-cases/deserialization/string.js b/test/fixtures/serde-test-cases/deserialization/string.js new file mode 100644 index 00000000..d50855bd --- /dev/null +++ b/test/fixtures/serde-test-cases/deserialization/string.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = [ + { + name: 'Unicode code point escapes', + value: '💚💛', + serialized: '\'\\u{1F49A}\\u{1F49B}\'' + } +]; diff --git a/test/fixtures/serde-test-cases/index.js b/test/fixtures/serde-test-cases/index.js index c064c611..ebbf62e5 100644 --- a/test/fixtures/serde-test-cases/index.js +++ b/test/fixtures/serde-test-cases/index.js @@ -4,5 +4,5 @@ module.exports = { serde: require('./serde'), serialization: require('./serialization'), deserialization: require('./deserialization'), - invalidDeserialization: require('./deserialization-invalid') + invalid: require('./invalid') }; diff --git a/test/fixtures/serde-test-cases/deserialization-invalid.js b/test/fixtures/serde-test-cases/invalid/index.js similarity index 96% rename from test/fixtures/serde-test-cases/deserialization-invalid.js rename to test/fixtures/serde-test-cases/invalid/index.js index 6c25b72f..7bbafcf8 100644 --- a/test/fixtures/serde-test-cases/deserialization-invalid.js +++ b/test/fixtures/serde-test-cases/invalid/index.js @@ -22,7 +22,7 @@ module.exports = [ value: '\'\\u{\'' }, { - name: 'illegal input $6', + name: 'illegal input #6', value: '\'\\u{}\'' }, { diff --git a/test/fixtures/serde-test-cases/serde.js b/test/fixtures/serde-test-cases/serde.js deleted file mode 100644 index 4c036c33..00000000 --- a/test/fixtures/serde-test-cases/serde.js +++ /dev/null @@ -1,141 +0,0 @@ -'use strict'; - -module.exports = [ - { - name: 'true', - value: true, - serialized: 'true' - }, - { - name: 'false', - value: false, - serialized: 'false' - }, - { - name: 'integer', - value: 42, - serialized: '42' - }, - { - name: 'negative integer', - value: -3, - serialized: '-3' - }, - { - name: 'float', - value: 1e100, - serialized: '1e+100' - }, - { - name: 'float with comma', - value: 3.14, - serialized: '3.14' - }, - { - name: 'small float', - value: 1e-3, - serialized: '0.001' - }, - { - name: 'undefined', - value: undefined, - serialized: 'undefined' - }, - { - name: 'null', - value: null, - serialized: 'null' - }, - { - name: 'string', - value: 'str', - serialized: '\'str\'' - }, - { - name: 'string with endline', - value: 'first\nsecond', - serialized: '\'first\\nsecond\'' - }, - { - name: 'string with single quote', - value: 'it\'s', - serialized: '\'it\\\'s\'' - }, - { - name: 'string with Unicode escape sequences', - value: '01\u0000\u0001', - serialized: '\'01\\u0000\\u0001\'' - }, - { - name: 'empty array', - value: [], - serialized: '[]' - }, - { - name: 'array of integers', - value: [1, 2, 3], - serialized: '[1,2,3]' - }, - { - name: 'nested arrays', - value: ['outer', ['inner']], - serialized: '[\'outer\',[\'inner\']]' - }, - { - name: 'empty object', - value: {}, - serialized: '{}' - }, - { - name: 'object', - value: { field1: 'value', field2: null }, - serialized: '{field1:\'value\',field2:null}' - }, - { - name: 'Marcus array', - value: [ - 'Marcus Aurelius', - 'AE127095', - [ - '1990-02-15T00:00:00.000Z', - 'Rome' - ], - [ - 'Ukraine', - 'Kiev', - '03056', - 'Pobedy', - '37', - '1', - '158' - ] - ], - serialized: '[\'Marcus Aurelius\',\'AE127095\',' + - '[\'1990-02-15T00:00:00.000Z\',\'Rome\'],' + - '[\'Ukraine\',\'Kiev\',\'03056\',\'Pobedy\',\'37\',\'1\',\'158\']]' - }, - { - name: 'Marcus object', - value: { - name: 'Marcus Aurelius', - passport: 'AE127095', - birth: { - date: '1990-02-15T00:00:00.000Z', - place: 'Rome' - }, - address: { - country: 'Ukraine', - city: 'Kiev', - zip: '03056', - street: 'Pobedy', - building: '37', - floor: '1', - room: '158' - } - }, - serialized: '{name:\'Marcus Aurelius\',passport:\'AE127095\',' + - 'birth:{date:\'1990-02-15T00:00:00.000Z\',place:\'Rome\'},' + - 'address:{country:\'Ukraine\',city:\'Kiev\',zip:\'03056\',' + - 'street:\'Pobedy\',building:\'37\',floor:\'1\',room:\'158\'}}' - } -]; diff --git a/test/fixtures/serde-test-cases/serde/array.js b/test/fixtures/serde-test-cases/serde/array.js new file mode 100644 index 00000000..280efa0a --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/array.js @@ -0,0 +1,42 @@ +'use strict'; + +module.exports = [ + { + name: 'empty array', + value: [], + serialized: '[]' + }, + { + name: 'array of integers', + value: [1, 2, 3], + serialized: '[1,2,3]' + }, + { + name: 'nested arrays', + value: ['outer', ['inner']], + serialized: '[\'outer\',[\'inner\']]' + }, + { + name: 'Marcus array', + value: [ + 'Marcus Aurelius', + 'AE127095', + [ + '1990-02-15T00:00:00.000Z', + 'Rome' + ], + [ + 'Ukraine', + 'Kiev', + '03056', + 'Pobedy', + '37', + '1', + '158' + ] + ], + serialized: '[\'Marcus Aurelius\',\'AE127095\',' + + '[\'1990-02-15T00:00:00.000Z\',\'Rome\'],' + + '[\'Ukraine\',\'Kiev\',\'03056\',\'Pobedy\',\'37\',\'1\',\'158\']]' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/boolean.js b/test/fixtures/serde-test-cases/serde/boolean.js new file mode 100644 index 00000000..20d67673 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/boolean.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = [ + { + name: 'true', + value: true, + serialized: 'true' + }, + { + name: 'false', + value: false, + serialized: 'false' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/index.js b/test/fixtures/serde-test-cases/serde/index.js new file mode 100644 index 00000000..7ef6e8c3 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/index.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = [].concat( + require('./boolean'), + require('./number'), + require('./string'), + require('./null'), + require('./undefined'), + require('./array'), + require('./object') +); diff --git a/test/fixtures/serde-test-cases/serde/null.js b/test/fixtures/serde-test-cases/serde/null.js new file mode 100644 index 00000000..31d11449 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/null.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = [ + { + name: 'null', + value: null, + serialized: 'null' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/number.js b/test/fixtures/serde-test-cases/serde/number.js new file mode 100644 index 00000000..399b44e9 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/number.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = [ + { + name: 'integer', + value: 42, + serialized: '42' + }, + { + name: 'negative integer', + value: -3, + serialized: '-3' + }, + { + name: 'float', + value: 1e100, + serialized: '1e+100' + }, + { + name: 'float with comma', + value: 3.14, + serialized: '3.14' + }, + { + name: 'small float', + value: 1e-3, + serialized: '0.001' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/object.js b/test/fixtures/serde-test-cases/serde/object.js new file mode 100644 index 00000000..7a4af1d1 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/object.js @@ -0,0 +1,38 @@ +'use strict'; + +module.exports = [ + { + name: 'empty object', + value: {}, + serialized: '{}' + }, + { + name: 'object', + value: { field1: 'value', field2: null }, + serialized: '{field1:\'value\',field2:null}' + }, + { + name: 'Marcus object', + value: { + name: 'Marcus Aurelius', + passport: 'AE127095', + birth: { + date: '1990-02-15T00:00:00.000Z', + place: 'Rome' + }, + address: { + country: 'Ukraine', + city: 'Kiev', + zip: '03056', + street: 'Pobedy', + building: '37', + floor: '1', + room: '158' + } + }, + serialized: '{name:\'Marcus Aurelius\',passport:\'AE127095\',' + + 'birth:{date:\'1990-02-15T00:00:00.000Z\',place:\'Rome\'},' + + 'address:{country:\'Ukraine\',city:\'Kiev\',zip:\'03056\',' + + 'street:\'Pobedy\',building:\'37\',floor:\'1\',room:\'158\'}}' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/string.js b/test/fixtures/serde-test-cases/serde/string.js new file mode 100644 index 00000000..f6aa65ac --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/string.js @@ -0,0 +1,24 @@ +'use strict'; + +module.exports = [ + { + name: 'string', + value: 'str', + serialized: '\'str\'' + }, + { + name: 'string with endline', + value: 'first\nsecond', + serialized: '\'first\\nsecond\'' + }, + { + name: 'string with single quote', + value: 'it\'s', + serialized: '\'it\\\'s\'' + }, + { + name: 'string with Unicode escape sequences', + value: '01\u0000\u0001', + serialized: '\'01\\u0000\\u0001\'' + } +]; diff --git a/test/fixtures/serde-test-cases/serde/undefined.js b/test/fixtures/serde-test-cases/serde/undefined.js new file mode 100644 index 00000000..45e251a3 --- /dev/null +++ b/test/fixtures/serde-test-cases/serde/undefined.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = [ + { + name: 'undefined', + value: undefined, + serialized: 'undefined' + } +]; diff --git a/test/fixtures/serde-test-cases/serialization/array.js b/test/fixtures/serde-test-cases/serialization/array.js new file mode 100644 index 00000000..512c69d6 --- /dev/null +++ b/test/fixtures/serde-test-cases/serialization/array.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = [ + { + name: 'sparse arrays', + // eslint-disable-next-line no-sparse-arrays + value: [1, , 3], + serialized: '[1,,3]' + } +]; diff --git a/test/fixtures/serde-test-cases/serialization/index.js b/test/fixtures/serde-test-cases/serialization/index.js new file mode 100644 index 00000000..2f5fe163 --- /dev/null +++ b/test/fixtures/serde-test-cases/serialization/index.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = [].concat( + require('./array'), + require('./object') +); diff --git a/test/fixtures/serde-test-cases/serialization.js b/test/fixtures/serde-test-cases/serialization/object.js similarity index 75% rename from test/fixtures/serde-test-cases/serialization.js rename to test/fixtures/serde-test-cases/serialization/object.js index 825eb288..7090dbac 100644 --- a/test/fixtures/serde-test-cases/serialization.js +++ b/test/fixtures/serde-test-cases/serialization/object.js @@ -1,12 +1,6 @@ 'use strict'; module.exports = [ - { - name: 'sparse arrays', - // eslint-disable-next-line no-sparse-arrays - value: [1, , 3], - serialized: '[1,,3]' - }, { name: 'object omitting undefined fields', value: { field1: 'value', field2: undefined }, diff --git a/test/node/serde.js b/test/node/serde.js index 58a785b8..51a55627 100644 --- a/test/node/serde.js +++ b/test/node/serde.js @@ -20,7 +20,7 @@ testCases.serde.concat(testCases.deserialization).forEach((testCase) => { }); }); -testCases.invalidDeserialization.forEach((testCase) => { +testCases.invalid.forEach((testCase) => { test(`must not allow ${testCase.name}`, (test) => { test.throws(() => jstp.parse(testCase.value)); test.end();