Skip to content

Commit

Permalink
test: add tests for number parsing
Browse files Browse the repository at this point in the history
PR-URL: #241
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
  • Loading branch information
nechaido authored and belochub committed Jan 22, 2018
1 parent d22a6ba commit 2e45230
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/todo/serde/deserialization/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

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

module.exports = [
{
name: 'binary number starting with 0b',
value: 42,
serialized: '0b101010'
},
{
name: 'binary number starting with 0B',
value: 42,
serialized: '0B101010'
},
{
name: 'octal number starting with 0o',
value: 42,
serialized: '0o52'
},
{
name: 'octal number starting with 0O',
value: 42,
serialized: '0O52'
},
{
name: 'hex number starting with 0x',
value: 42,
serialized: '0x2a'
},
{
name: 'hex number starting with 0X',
value: 42,
serialized: '0X2A'
}
];
6 changes: 6 additions & 0 deletions test/fixtures/todo/serde/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
serialization: require('./serialization'),
deserialization: require('./deserialization'),
};
11 changes: 9 additions & 2 deletions test/todo/serde.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
const jstp = require('../..');

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

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

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

0 comments on commit 2e45230

Please sign in to comment.