Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env newlisp
- ;; JSON_checker for newLISP
- ;; http://www.json.org/JSON_checker/
- (setf json-data-alist
- '(("pass1.json" [text][
- "JSON Test Pattern pass1",
- {"object with 1 member":["array with 1 element"]},
- {},
- [],
- -42,
- true,
- false,
- null,
- {
- "integer": 1234567890,
- "real": -9876.543210,
- "e": 0.123456789e-12,
- "E": 1.234567890E+34,
- "": 23456789012E66,
- "zero": 0,
- "one": 1,
- "space": " ",
- "quote": "\"",
- "backslash": "\\",
- "controls": "\b\f\n\r\t",
- "slash": "/ & \/",
- "alpha": "abcdefghijklmnopqrstuvwyz",
- "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
- "digit": "0123456789",
- "0123456789": "digit",
- "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
- "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
- "true": true,
- "false": false,
- "null": null,
- "array":[ ],
- "object":{ },
- "address": "50 St. James Street",
- "url": "http://www.JSON.org/",
- "comment": "// /* <!-- --",
- "# -- --> */": " ",
- " s p a c e d " :[1,2 , 3
- ,
- 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
- "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
- "quotes": "" \u0022 %22 0x22 034 "",
- "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
- : "A key can be any string"
- },
- 0.5 ,98.6
- ,
- 99.44
- ,
- 1066,
- 1e1,
- 0.1e1,
- 1e-1,
- 1e00,2e+00,2e-00
- ,"rosebud"][/text])
- ("pass2.json" "[[[[[[[[[[[[[[[[[[[\"Not too deep\"]]]]]]]]]]]]]]]]]]]")
- ("pass3.json" "{\n \"JSON Test Pattern pass3\": {\n \"The outermost value\": \"must be an object or array.\",\n \"In this test\": \"It is an object.\"\n }\n}\n")
- ("fail1.json" "\"A JSON payload should be an object or array, not a string.\"")
- ("fail2.json" "[\"Unclosed array\"")
- ("fail3.json" "{unquoted_key: \"keys must be quoted\"}")
- ("fail4.json" "[\"extra comma\",]")
- ("fail5.json" "[\"double extra comma\",,]")
- ("fail6.json" "[ , \"<-- missing value\"]")
- ("fail7.json" "[\"Comma after the close\"],")
- ("fail8.json" "[\"Extra close\"]]")
- ("fail9.json" "{\"Extra comma\": true,}")
- ("fail10.json" "{\"Extra value after close\": true} \"misplaced quoted value\"")
- ("fail11.json" "{\"Illegal expression\": 1 + 2}")
- ("fail12.json" "{\"Illegal invocation\": alert()}")
- ("fail13.json" "{\"Numbers cannot have leading zeroes\": 013}")
- ("fail14.json" "{\"Numbers cannot be hex\": 0x14}")
- ("fail15.json" "[\"Illegal backslash escape: \\x15\"]")
- ("fail16.json" "[\\naked]")
- ("fail17.json" "[\"Illegal backslash escape: \\017\"]")
- ("fail18.json" "[[[[[[[[[[[[[[[[[[[[\"Too deep\"]]]]]]]]]]]]]]]]]]]]")
- ("fail19.json" "{\"Missing colon\" null}")
- ("fail20.json" "{\"Double colon\":: null}")
- ("fail21.json" "{\"Comma instead of colon\", null}")
- ("fail22.json" "[\"Colon instead of comma\": false]")
- ("fail23.json" "[\"Bad value\", truth]")
- ("fail24.json" "['single quote']")
- ("fail25.json" "[\"\ttab\tcharacter\tin\tstring\t\"]")
- ("fail26.json" "[\"tab\\ character\\ in\\ string\\ \"]")
- ("fail27.json" "[\"line\nbreak\"]")
- ("fail28.json" "[\"line\\\nbreak\"]")
- ("fail29.json" "[0e]")
- ("fail30.json" "[0e+]")
- ("fail31.json" "[0e+-1]")
- ("fail32.json" "{\"Comma instead if closing brace\": true,")
- ("fail33.json" "[\"mismatch\"}")
- ))
- (dolist (kv json-data-alist)
- (let ((res (json-parse (kv 1)))
- (pass (nil? (json-error))))
- (unless (or (and (starts-with (kv 0) "pass") pass)
- (and (starts-with (kv 0) "fail") (not pass)))
- (println (kv 0) " -> " (if pass "pass" "fail") " : " (kv 1)))
- ))
- (exit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement