json.reader: read Infinity, -Infinity and NaN
parent
496ff53f22
commit
5ed3aef603
|
@ -1,5 +1,5 @@
|
|||
USING: assocs arrays json.reader kernel strings tools.test
|
||||
hashtables json io.streams.string ;
|
||||
hashtables json io.streams.string math ;
|
||||
IN: json.reader.tests
|
||||
|
||||
{ f } [ "false" json> ] unit-test
|
||||
|
@ -72,3 +72,7 @@ IN: json.reader.tests
|
|||
"\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\""
|
||||
json>
|
||||
] unit-test
|
||||
|
||||
{ 1/0. } [ "Infinity" json> ] unit-test
|
||||
{ -1/0. } [ "-Infinity" json> ] unit-test
|
||||
{ t } [ "NaN" json> fp-nan? ] unit-test
|
||||
|
|
|
@ -12,7 +12,12 @@ IN: json.reader
|
|||
|
||||
: json-number ( char stream -- num char )
|
||||
[ 1string ] [ "\s\t\r\n,:}]" swap stream-read-until ] bi*
|
||||
[ append string>number ] dip ;
|
||||
[ append {
|
||||
{ "Infinity" [ 1/0. ] }
|
||||
{ "-Infinity" [ -1/0. ] }
|
||||
{ "NaN" [ 0/0. ] }
|
||||
[ string>number ]
|
||||
} case ] dip ;
|
||||
|
||||
: json-expect ( token stream -- )
|
||||
[ dup length ] [ stream-read ] bi* = [ json-error ] unless ; inline
|
||||
|
|
Loading…
Reference in New Issue