Skip to content

Commit

Permalink
test: add tests for number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nechaido committed Jun 27, 2017
1 parent ae15933 commit b13c8cf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/todo/json5/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/json5/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/json5/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/json5-serde.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
const jstp = require('../..');

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

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

testCases.deserialization.forEach((testCase) => {
test(`must deserialize ${testCase.name}`, (test) => {
test.strictSame(jstp.parse(testCase.serialized), testCase.value);
test.end();
});
});
13 changes: 0 additions & 13 deletions test/todo/json5-serializer.js

This file was deleted.

File renamed without changes.

0 comments on commit b13c8cf

Please sign in to comment.