diff --git a/serialize2.js b/serialize2.js index 65d5c15..f250db2 100644 --- a/serialize2.js +++ b/serialize2.js @@ -347,10 +347,10 @@ module.eJSON = { debug.lex('number', str, i, line) // special cases.., if(match == 'Infinity'){ - return [Infinity, i, line] } + return [Infinity, i+'Infinity'.length, line] } if(match == '-' - && str.slice(i, 'Infinity'.length) == 'Infinity'){ - return [-Infinity, i+'Infinity'.length, line] } + && str.slice(i, i+'-Infinity'.length) == '-Infinity'){ + return [-Infinity, i+'-Infinity'.length, line] } // numbers... var j = i+1 while(j < str.length diff --git a/test.js b/test.js index 140e9e7..3600d74 100755 --- a/test.js +++ b/test.js @@ -16,9 +16,26 @@ var eJSON = require('./serialize2') //--------------------------------------------------------------------- // XXX split into pure and extended JSON... +// XXX test whitespace handling... var setups = test.Setups({ number: function(assert){ 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){ return '"string"' }, 'true': function(assert){ @@ -35,7 +52,13 @@ var setups = test.Setups({ 'array-empty': function(assert){ return '[]' }, - 'array-sparse': function(assert){ + 'array-sparse-a': function(assert){ + return '[]' }, + 'array-sparse-b': function(assert){ + return '["a",]' }, + 'array-sparse-c': function(assert){ + return '[,"a"]' }, + 'array-sparse-d': function(assert){ return '[,1,,,2,]' }, 'array-recursive': function(assert){ return '[]' }, @@ -53,16 +76,23 @@ var setups = test.Setups({ }) 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){ - return `[${ setup }]` }, + return eJSON.serialize( + [ eJSON.deserialize(setup) ] ) }, 'object-stuffed': function(assert, setup){ - return `{"key":${ setup }}` }, + return eJSON.serialize( + { key: eJSON.deserialize(setup) } ) }, 'set-stuffed': function(assert, setup){ - return `Set([${ setup }])` }, + return eJSON.serialize( + new Set([ eJSON.deserialize(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){ - return `Map([["key",${ setup }]])` }, + return eJSON.serialize( + new Map([["key", eJSON.deserialize(setup)]]) ) }, }) test.Tests({