Skip to content

Commit

Permalink
test: refactor fixtures for serde tests
Browse files Browse the repository at this point in the history
PR-URL: #236
Reviewed-By: Mykola Bilochub <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
  • Loading branch information
nechaido authored and belochub committed Jan 22, 2018
1 parent 6472e12 commit 5c2a90b
Show file tree
Hide file tree
Showing 21 changed files with 264 additions and 199 deletions.
49 changes: 0 additions & 49 deletions test/fixtures/serde-test-cases/deserialization.js

This file was deleted.

9 changes: 9 additions & 0 deletions test/fixtures/serde-test-cases/deserialization/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = [
{
name: 'sparse array',
value: [1, undefined, 3],
serialized: '[1,,3]'
}
];
8 changes: 8 additions & 0 deletions test/fixtures/serde-test-cases/deserialization/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = [].concat(
require('./number'),
require('./string'),
require('./array'),
require('./object')
);
24 changes: 24 additions & 0 deletions test/fixtures/serde-test-cases/deserialization/number.js
Original file line number Diff line number Diff line change
@@ -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'
}
];
19 changes: 19 additions & 0 deletions test/fixtures/serde-test-cases/deserialization/object.js
Original file line number Diff line number Diff line change
@@ -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}'
}
];
9 changes: 9 additions & 0 deletions test/fixtures/serde-test-cases/deserialization/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = [
{
name: 'Unicode code point escapes',
value: '💚💛',
serialized: '\'\\u{1F49A}\\u{1F49B}\''
}
];
2 changes: 1 addition & 1 deletion test/fixtures/serde-test-cases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
serde: require('./serde'),
serialization: require('./serialization'),
deserialization: require('./deserialization'),
invalidDeserialization: require('./deserialization-invalid')
invalid: require('./invalid')
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = [
value: '\'\\u{\''
},
{
name: 'illegal input $6',
name: 'illegal input #6',
value: '\'\\u{}\''
},
{
Expand Down
141 changes: 0 additions & 141 deletions test/fixtures/serde-test-cases/serde.js

This file was deleted.

42 changes: 42 additions & 0 deletions test/fixtures/serde-test-cases/serde/array.js
Original file line number Diff line number Diff line change
@@ -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\']]'
}
];
14 changes: 14 additions & 0 deletions test/fixtures/serde-test-cases/serde/boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = [
{
name: 'true',
value: true,
serialized: 'true'
},
{
name: 'false',
value: false,
serialized: 'false'
}
];
11 changes: 11 additions & 0 deletions test/fixtures/serde-test-cases/serde/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

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

module.exports = [
{
name: 'null',
value: null,
serialized: 'null'
}
];
29 changes: 29 additions & 0 deletions test/fixtures/serde-test-cases/serde/number.js
Original file line number Diff line number Diff line change
@@ -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'
}
];
Loading

0 comments on commit 5c2a90b

Please sign in to comment.