| 
									
										
										
										
											2015-07-28 21:10:24 -04:00
										 |  |  | USING: hashtables io.streams.string json json.reader | 
					
						
							|  |  |  | json.reader.private kernel literals math strings tools.test ;
 | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | IN: json.reader.tests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { f } [ "false" json> ] unit-test | 
					
						
							|  |  |  | { t } [ "true" json> ] unit-test | 
					
						
							|  |  |  | { json-null } [ "null" json> ] unit-test | 
					
						
							|  |  |  | { 0 } [ "0" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2016-03-05 09:56:18 -05:00
										 |  |  | { 0 } [ "-0" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | { 102 } [ "102" json> ] unit-test | 
					
						
							|  |  |  | { -102 } [ "-102" json> ] unit-test | 
					
						
							|  |  |  | { 102 } [ "+102" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-07 23:00:19 -05:00
										 |  |  | { 1000.0 } [ "1.0e3" json> ] unit-test | 
					
						
							|  |  |  | { 1000.0 } [ "10e2" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | { 102.0 } [ "102.0" json> ] unit-test | 
					
						
							|  |  |  | { 102.5 } [ "102.5" json> ] unit-test | 
					
						
							|  |  |  | { 102.5 } [ "102.50" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-09-02 16:09:14 -04:00
										 |  |  | { -10250.0 } [ "-102.5e2" json> ] unit-test | 
					
						
							|  |  |  | { -10250.0 } [ "-102.5E+2" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2016-03-05 09:56:18 -05:00
										 |  |  | { -1.025 } [ "-102.5E-2" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-07 23:00:19 -05:00
										 |  |  | { 10.25 } [ "1025e-2" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 12:10:11 -04:00
										 |  |  | { 0.125 } [ "0.125" json> ] unit-test | 
					
						
							|  |  |  | { -0.125 } [ "-0.125" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2009-05-29 17:41:24 -04:00
										 |  |  | { -0.00125 } [ "-0.125e-2" json> ] unit-test | 
					
						
							|  |  |  | { -012.5 } [ "-0.125e+2" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2016-03-05 09:56:18 -05:00
										 |  |  | { 0.0 } [ "123e-10000000" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-08 15:08:58 -05:00
										 |  |  | ! not widely supported by javascript, but allowed in the grammar, and a nice | 
					
						
							|  |  |  | ! feature to get | 
					
						
							|  |  |  | { -0.0 } [ "-0.0" json> ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | { " fuzzy  pickles " } [ "  \" fuzzy  pickles \" "  json> ] unit-test | 
					
						
							|  |  |  | { "while 1:\n\tpass" } [ "  \"while 1:\n\tpass\" "  json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-08 15:08:58 -05:00
										 |  |  | ! unicode is allowed in json | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | { "ß∂¬ƒ˚∆" } [ "  \"ß∂¬ƒ˚∆\""  json> ] unit-test | 
					
						
							|  |  |  | ${ { 8 9 10 12 13 34 47 92 } >string } [ " \"\\b\\t\\n\\f\\r\\\"\\/\\\\\" " json> ] unit-test | 
					
						
							|  |  |  | ${ { 0xabcd } >string } [ " \"\\uaBCd\" " json> ] unit-test | 
					
						
							| 
									
										
										
										
											2015-06-10 18:25:19 -04:00
										 |  |  | { "𝄞" } [ "\"\\ud834\\udd1e\"" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-06 23:49:44 -04:00
										 |  |  | { H{ { "a" { } } { "b" 123 } } } [ "{\"a\":[],\"b\":123}" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2015-07-02 13:34:01 -04:00
										 |  |  | { { } } [ "[]" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | { { 1 "two" 3.0 } } [ " [1, \"two\", 3.0] " json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-07 23:00:19 -05:00
										 |  |  | { H{ } } [ "{}" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-08 15:08:58 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! the returned hashtable should be different every time | 
					
						
							| 
									
										
										
										
											2008-11-08 16:45:45 -05:00
										 |  |  | { H{ } } [ "key" "value" "{}" json> ?set-at "{}" json> nip ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-08 15:08:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | { H{ { "US$" 1.0 } { "EU€" 1.5 } } } [ " { \"US$\":1.00, \"EU\\u20AC\":1.50 } " json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | { H{ | 
					
						
							|  |  |  |     { "fib" { 1 1 2 3 5 8 H{ { "etc" "etc" } } } } | 
					
						
							|  |  |  |     { "prime" { 2 3 5 7 11 13 } } | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | } } [ " { | 
					
						
							|  |  |  |     \"fib\": [1, 1,  2,   3,     5,         8, | 
					
						
							|  |  |  |         { \"etc\":\"etc\" } ], | 
					
						
							|  |  |  |     \"prime\": | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  |     [ 2,3,     5,7, | 
					
						
							|  |  |  | 11, | 
					
						
							|  |  |  | 13
 | 
					
						
							|  |  |  | ]      } | 
					
						
							| 
									
										
										
										
											2015-07-26 01:59:56 -04:00
										 |  |  | " json> ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-31 01:46:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | { 0 } [ "      0" json> ] unit-test | 
					
						
							|  |  |  | { 0 } [ "0      " json> ] unit-test | 
					
						
							|  |  |  | { 0 } [ "   0   " json> ] unit-test | 
					
						
							| 
									
										
										
										
											2009-12-24 18:48:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-03 16:11:47 -04:00
										 |  |  | { V{ H{ { "a" "b" } } H{ { "c" "d" } } } } | 
					
						
							| 
									
										
										
										
											2015-08-03 15:23:08 -04:00
										 |  |  | [ "{\"a\": \"b\"} {\"c\": \"d\"}" [ read-json-objects ] with-string-reader ] unit-test | 
					
						
							| 
									
										
										
										
											2010-06-03 16:11:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-24 18:48:16 -05:00
										 |  |  | ! empty objects are allowed as values in objects | 
					
						
							|  |  |  | { H{ { "foo" H{ } } } } [ "{ \"foo\" : {}}" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2016-03-05 09:56:18 -05:00
										 |  |  | ! And arrays | 
					
						
							|  |  |  | { { H{ } } } [ "[{}]" json> ] unit-test | 
					
						
							| 
									
										
										
										
											2014-11-27 17:52:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     "\0\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\e\x1c\x1d\x1e\x1f" | 
					
						
							|  |  |  | } [ | 
					
						
							|  |  |  |     "\"\\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 | 
					
						
							| 
									
										
										
										
											2015-06-10 18:46:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | { 1/0. } [ "Infinity" json> ] unit-test | 
					
						
							|  |  |  | { -1/0. } [ "-Infinity" json> ] unit-test | 
					
						
							|  |  |  | { t } [ "NaN" json> fp-nan? ] unit-test | 
					
						
							| 
									
										
										
										
											2015-07-28 21:10:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "<!doctype html>\n<html>\n<head>\n   " json> ] | 
					
						
							|  |  |  | [ not-a-json-number? ] must-fail-with | 
					
						
							| 
									
										
										
										
											2015-08-03 15:23:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | { H{ } } [ "" json> ] unit-test |