-USING: hashtables io.streams.string json json.reader kernel
-literals math strings tools.test ;
+USING: hashtables io.streams.string json json.reader
+json.reader.private kernel literals math strings tools.test ;
IN: json.reader.tests
{ f } [ "false" json> ] unit-test
{ 1/0. } [ "Infinity" json> ] unit-test
{ -1/0. } [ "-Infinity" json> ] unit-test
{ t } [ "NaN" json> fp-nan? ] unit-test
+
+[ "<!doctype html>\n<html>\n<head>\n " json> ]
+[ not-a-json-number? ] must-fail-with
<PRIVATE
+ERROR: not-a-json-number string ;
+
: json-number ( char stream -- num char )
[ 1string ] [ "\s\t\r\n,:}]" swap stream-read-until ] bi*
- [ append {
- { "Infinity" [ 1/0. ] }
- { "-Infinity" [ -1/0. ] }
- { "NaN" [ 0/0. ] }
- [ string>number ]
- } case ] dip ;
+ [
+ append {
+ { "Infinity" [ 1/0. ] }
+ { "-Infinity" [ -1/0. ] }
+ { "NaN" [ 0/0. ] }
+ [ dup string>number [ nip ] [ not-a-json-number ] if* ]
+ } case
+ ] dip ;
: json-expect ( token stream -- )
[ dup length ] [ stream-read ] bi* = [ json-error ] unless ; inline