mirror of
https://github.com/flynx/serialize.js.git
synced 2026-07-13 12:30:57 +00:00
better testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6f9eb29957
commit
1b32230033
@ -347,10 +347,10 @@ module.eJSON = {
|
|||||||
debug.lex('number', str, i, line)
|
debug.lex('number', str, i, line)
|
||||||
// special cases..,
|
// special cases..,
|
||||||
if(match == 'Infinity'){
|
if(match == 'Infinity'){
|
||||||
return [Infinity, i, line] }
|
return [Infinity, i+'Infinity'.length, line] }
|
||||||
if(match == '-'
|
if(match == '-'
|
||||||
&& str.slice(i, 'Infinity'.length) == 'Infinity'){
|
&& str.slice(i, i+'-Infinity'.length) == '-Infinity'){
|
||||||
return [-Infinity, i+'Infinity'.length, line] }
|
return [-Infinity, i+'-Infinity'.length, line] }
|
||||||
// numbers...
|
// numbers...
|
||||||
var j = i+1
|
var j = i+1
|
||||||
while(j < str.length
|
while(j < str.length
|
||||||
|
|||||||
42
test.js
42
test.js
@ -16,9 +16,26 @@ var eJSON = require('./serialize2')
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// XXX split into pure and extended JSON...
|
// XXX split into pure and extended JSON...
|
||||||
|
|
||||||
|
// XXX test whitespace handling...
|
||||||
var setups = test.Setups({
|
var setups = test.Setups({
|
||||||
number: function(assert){
|
number: function(assert){
|
||||||
return '123' },
|
return '123' },
|
||||||
|
'float-a': function(assert){
|
||||||
|
return '0.123' },
|
||||||
|
'float-b': function(assert){
|
||||||
|
return '1.23' },
|
||||||
|
// XXX need a way to test this...
|
||||||
|
//'float-a': function(assert){
|
||||||
|
// return '.123' },
|
||||||
|
//'float-c': function(assert){
|
||||||
|
// return '123.' },
|
||||||
|
// XXX also test:
|
||||||
|
// hex/bin/orc/...
|
||||||
|
Infinity: function(assert){
|
||||||
|
return 'Infinity' },
|
||||||
|
nInfinity: function(assert){
|
||||||
|
return '-Infinity' },
|
||||||
|
// XXX also test diffrerent quotations...
|
||||||
string: function(assert){
|
string: function(assert){
|
||||||
return '"string"' },
|
return '"string"' },
|
||||||
'true': function(assert){
|
'true': function(assert){
|
||||||
@ -35,7 +52,13 @@ var setups = test.Setups({
|
|||||||
|
|
||||||
'array-empty': function(assert){
|
'array-empty': function(assert){
|
||||||
return '[]' },
|
return '[]' },
|
||||||
'array-sparse': function(assert){
|
'array-sparse-a': function(assert){
|
||||||
|
return '[<empty>]' },
|
||||||
|
'array-sparse-b': function(assert){
|
||||||
|
return '["a",<empty>]' },
|
||||||
|
'array-sparse-c': function(assert){
|
||||||
|
return '[<empty>,"a"]' },
|
||||||
|
'array-sparse-d': function(assert){
|
||||||
return '[<empty>,1,<empty>,<empty>,2,<empty>]' },
|
return '[<empty>,1,<empty>,<empty>,2,<empty>]' },
|
||||||
'array-recursive': function(assert){
|
'array-recursive': function(assert){
|
||||||
return '[<RECURSIVE[]>]' },
|
return '[<RECURSIVE[]>]' },
|
||||||
@ -53,16 +76,23 @@ var setups = test.Setups({
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.Modifiers({
|
test.Modifiers({
|
||||||
|
// NOTE: we are not simply editing strings as we'll need to also
|
||||||
|
// update all the recursion paths which is not trivial...
|
||||||
'array-stuffed': function(assert, setup){
|
'array-stuffed': function(assert, setup){
|
||||||
return `[${ setup }]` },
|
return eJSON.serialize(
|
||||||
|
[ eJSON.deserialize(setup) ] ) },
|
||||||
'object-stuffed': function(assert, setup){
|
'object-stuffed': function(assert, setup){
|
||||||
return `{"key":${ setup }}` },
|
return eJSON.serialize(
|
||||||
|
{ key: eJSON.deserialize(setup) } ) },
|
||||||
'set-stuffed': function(assert, setup){
|
'set-stuffed': function(assert, setup){
|
||||||
return `Set([${ setup }])` },
|
return eJSON.serialize(
|
||||||
|
new Set([ eJSON.deserialize(setup) ]) ) },
|
||||||
'map-key-stuffed': function(assert, setup){
|
'map-key-stuffed': function(assert, setup){
|
||||||
return `Map([[${ setup },"value"]])` },
|
return eJSON.serialize(
|
||||||
|
new Map([[eJSON.deserialize(setup), "value"]]) ) },
|
||||||
'map-value-stuffed': function(assert, setup){
|
'map-value-stuffed': function(assert, setup){
|
||||||
return `Map([["key",${ setup }]])` },
|
return eJSON.serialize(
|
||||||
|
new Map([["key", eJSON.deserialize(setup)]]) ) },
|
||||||
})
|
})
|
||||||
|
|
||||||
test.Tests({
|
test.Tests({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user