]> gitweb.factorcode.org Git - factor.git/commitdiff
json.reader: read Infinity, -Infinity and NaN
authorJon Harper <jon.harper87@gmail.com>
Wed, 10 Jun 2015 22:46:56 +0000 (00:46 +0200)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 11 Jun 2015 05:51:38 +0000 (22:51 -0700)
basis/json/reader/reader-tests.factor
basis/json/reader/reader.factor

index f33a127762addf1dbc1ee4f619d39f46cef84e14..758c79cd25a37fb06f96c5dc7a547ad67970649a 100644 (file)
@@ -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
index 91419399e07e1feb89dd0415899a49adcc78def1..f46226531a4bfd8119aa05080d6fd1817bbc5ba0 100644 (file)
@@ -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