kosh

json-test.lsp

Jun 28th, 2013
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env newlisp
  2.  
  3. ;; JSON_checker for newLISP
  4. ;; http://www.json.org/JSON_checker/
  5.  
  6. (setf json-data-alist
  7.       '(("pass1.json" [text][
  8.     "JSON Test Pattern pass1",
  9.     {"object with 1 member":["array with 1 element"]},
  10.     {},
  11.     [],
  12.     -42,
  13.     true,
  14.     false,
  15.     null,
  16.     {
  17.         "integer": 1234567890,
  18.         "real": -9876.543210,
  19.         "e": 0.123456789e-12,
  20.         "E": 1.234567890E+34,
  21.         "":  23456789012E66,
  22.         "zero": 0,
  23.         "one": 1,
  24.         "space": " ",
  25.         "quote": "\"",
  26.         "backslash": "\\",
  27.         "controls": "\b\f\n\r\t",
  28.         "slash": "/ & \/",
  29.         "alpha": "abcdefghijklmnopqrstuvwyz",
  30.         "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
  31.         "digit": "0123456789",
  32.         "0123456789": "digit",
  33.         "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
  34.         "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
  35.         "true": true,
  36.         "false": false,
  37.         "null": null,
  38.         "array":[  ],
  39.         "object":{  },
  40.         "address": "50 St. James Street",
  41.         "url": "http://www.JSON.org/",
  42.         "comment": "// /* <!-- --",
  43.         "# -- --> */": " ",
  44.         " s p a c e d " :[1,2 , 3
  45.  
  46. ,
  47.  
  48. 4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],
  49.         "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
  50.         "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
  51.         "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
  52. : "A key can be any string"
  53.     },
  54.     0.5 ,98.6
  55. ,
  56. 99.44
  57. ,
  58.  
  59. 1066,
  60. 1e1,
  61. 0.1e1,
  62. 1e-1,
  63. 1e00,2e+00,2e-00
  64. ,"rosebud"][/text])
  65.         ("pass2.json" "[[[[[[[[[[[[[[[[[[[\"Not too deep\"]]]]]]]]]]]]]]]]]]]")
  66.         ("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")
  67.         ("fail1.json" "\"A JSON payload should be an object or array, not a string.\"")
  68.         ("fail2.json" "[\"Unclosed array\"")
  69.         ("fail3.json" "{unquoted_key: \"keys must be quoted\"}")
  70.         ("fail4.json" "[\"extra comma\",]")
  71.         ("fail5.json" "[\"double extra comma\",,]")
  72.         ("fail6.json" "[   , \"<-- missing value\"]")
  73.         ("fail7.json" "[\"Comma after the close\"],")
  74.         ("fail8.json" "[\"Extra close\"]]")
  75.         ("fail9.json" "{\"Extra comma\": true,}")
  76.         ("fail10.json" "{\"Extra value after close\": true} \"misplaced quoted value\"")
  77.         ("fail11.json" "{\"Illegal expression\": 1 + 2}")
  78.         ("fail12.json" "{\"Illegal invocation\": alert()}")
  79.         ("fail13.json" "{\"Numbers cannot have leading zeroes\": 013}")
  80.         ("fail14.json" "{\"Numbers cannot be hex\": 0x14}")
  81.         ("fail15.json" "[\"Illegal backslash escape: \\x15\"]")
  82.         ("fail16.json" "[\\naked]")
  83.         ("fail17.json" "[\"Illegal backslash escape: \\017\"]")
  84.         ("fail18.json" "[[[[[[[[[[[[[[[[[[[[\"Too deep\"]]]]]]]]]]]]]]]]]]]]")
  85.         ("fail19.json" "{\"Missing colon\" null}")
  86.         ("fail20.json" "{\"Double colon\":: null}")
  87.         ("fail21.json" "{\"Comma instead of colon\", null}")
  88.         ("fail22.json" "[\"Colon instead of comma\": false]")
  89.         ("fail23.json" "[\"Bad value\", truth]")
  90.         ("fail24.json" "['single quote']")
  91.         ("fail25.json" "[\"\ttab\tcharacter\tin\tstring\t\"]")
  92.         ("fail26.json" "[\"tab\\   character\\   in\\  string\\  \"]")
  93.         ("fail27.json" "[\"line\nbreak\"]")
  94.         ("fail28.json" "[\"line\\\nbreak\"]")
  95.         ("fail29.json" "[0e]")
  96.         ("fail30.json" "[0e+]")
  97.         ("fail31.json" "[0e+-1]")
  98.         ("fail32.json" "{\"Comma instead if closing brace\": true,")
  99.         ("fail33.json" "[\"mismatch\"}")
  100.         ))
  101.  
  102. (dolist (kv json-data-alist)
  103.   (let ((res (json-parse (kv 1)))
  104.         (pass (nil? (json-error))))
  105.     (unless (or (and (starts-with (kv 0) "pass") pass)
  106.                 (and (starts-with (kv 0) "fail") (not pass)))
  107.       (println (kv 0) " -> " (if pass "pass" "fail") " : " (kv 1)))
  108.     ))
  109.  
  110. (exit)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×