Posted to tcl by mr_calvin at Fri Jul 14 10:55:54 GMT 2017view raw

  1. ÿÿÿADDED tests/data/jsonchecker/fail1.json
  2. Index: tests/data/jsonchecker/fail1.json
  3. ==================================================================
  4. --- tests/data/jsonchecker/fail1.json
  5. +++ tests/data/jsonchecker/fail1.json
  6. @@ -0,0 +1,1 @@
  7. +"A JSON payload should be an object or array, not a string."
  8.  
  9. ADDED tests/data/jsonchecker/fail10.json
  10. Index: tests/data/jsonchecker/fail10.json
  11. ==================================================================
  12. --- tests/data/jsonchecker/fail10.json
  13. +++ tests/data/jsonchecker/fail10.json
  14. @@ -0,0 +1,1 @@
  15. +{"Extra value after close": true} "misplaced quoted value"
  16.  
  17. ADDED tests/data/jsonchecker/fail11.json
  18. Index: tests/data/jsonchecker/fail11.json
  19. ==================================================================
  20. --- tests/data/jsonchecker/fail11.json
  21. +++ tests/data/jsonchecker/fail11.json
  22. @@ -0,0 +1,1 @@
  23. +{"Illegal expression": 1 + 2}
  24.  
  25. ADDED tests/data/jsonchecker/fail12.json
  26. Index: tests/data/jsonchecker/fail12.json
  27. ==================================================================
  28. --- tests/data/jsonchecker/fail12.json
  29. +++ tests/data/jsonchecker/fail12.json
  30. @@ -0,0 +1,1 @@
  31. +{"Illegal invocation": alert()}
  32.  
  33. ADDED tests/data/jsonchecker/fail13.json
  34. Index: tests/data/jsonchecker/fail13.json
  35. ==================================================================
  36. --- tests/data/jsonchecker/fail13.json
  37. +++ tests/data/jsonchecker/fail13.json
  38. @@ -0,0 +1,1 @@
  39. +{"Numbers cannot have leading zeroes": 013}
  40.  
  41. ADDED tests/data/jsonchecker/fail14.json
  42. Index: tests/data/jsonchecker/fail14.json
  43. ==================================================================
  44. --- tests/data/jsonchecker/fail14.json
  45. +++ tests/data/jsonchecker/fail14.json
  46. @@ -0,0 +1,1 @@
  47. +{"Numbers cannot be hex": 0x14}
  48.  
  49. ADDED tests/data/jsonchecker/fail15.json
  50. Index: tests/data/jsonchecker/fail15.json
  51. ==================================================================
  52. --- tests/data/jsonchecker/fail15.json
  53. +++ tests/data/jsonchecker/fail15.json
  54. @@ -0,0 +1,1 @@
  55. +["Illegal backslash escape: \x15"]
  56.  
  57. ADDED tests/data/jsonchecker/fail16.json
  58. Index: tests/data/jsonchecker/fail16.json
  59. ==================================================================
  60. --- tests/data/jsonchecker/fail16.json
  61. +++ tests/data/jsonchecker/fail16.json
  62. @@ -0,0 +1,1 @@
  63. +[\naked]
  64.  
  65. ADDED tests/data/jsonchecker/fail17.json
  66. Index: tests/data/jsonchecker/fail17.json
  67. ==================================================================
  68. --- tests/data/jsonchecker/fail17.json
  69. +++ tests/data/jsonchecker/fail17.json
  70. @@ -0,0 +1,1 @@
  71. +["Illegal backslash escape: \017"]
  72.  
  73. ADDED tests/data/jsonchecker/fail18.json
  74. Index: tests/data/jsonchecker/fail18.json
  75. ==================================================================
  76. --- tests/data/jsonchecker/fail18.json
  77. +++ tests/data/jsonchecker/fail18.json
  78. @@ -0,0 +1,1 @@
  79. +[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
  80.  
  81. ADDED tests/data/jsonchecker/fail19.json
  82. Index: tests/data/jsonchecker/fail19.json
  83. ==================================================================
  84. --- tests/data/jsonchecker/fail19.json
  85. +++ tests/data/jsonchecker/fail19.json
  86. @@ -0,0 +1,1 @@
  87. +{"Missing colon" null}
  88.  
  89. ADDED tests/data/jsonchecker/fail2.json
  90. Index: tests/data/jsonchecker/fail2.json
  91. ==================================================================
  92. --- tests/data/jsonchecker/fail2.json
  93. +++ tests/data/jsonchecker/fail2.json
  94. @@ -0,0 +1,1 @@
  95. +["Unclosed array"
  96.  
  97. ADDED tests/data/jsonchecker/fail20.json
  98. Index: tests/data/jsonchecker/fail20.json
  99. ==================================================================
  100. --- tests/data/jsonchecker/fail20.json
  101. +++ tests/data/jsonchecker/fail20.json
  102. @@ -0,0 +1,1 @@
  103. +{"Double colon":: null}
  104.  
  105. ADDED tests/data/jsonchecker/fail21.json
  106. Index: tests/data/jsonchecker/fail21.json
  107. ==================================================================
  108. --- tests/data/jsonchecker/fail21.json
  109. +++ tests/data/jsonchecker/fail21.json
  110. @@ -0,0 +1,1 @@
  111. +{"Comma instead of colon", null}
  112.  
  113. ADDED tests/data/jsonchecker/fail22.json
  114. Index: tests/data/jsonchecker/fail22.json
  115. ==================================================================
  116. --- tests/data/jsonchecker/fail22.json
  117. +++ tests/data/jsonchecker/fail22.json
  118. @@ -0,0 +1,1 @@
  119. +["Colon instead of comma": false]
  120.  
  121. ADDED tests/data/jsonchecker/fail23.json
  122. Index: tests/data/jsonchecker/fail23.json
  123. ==================================================================
  124. --- tests/data/jsonchecker/fail23.json
  125. +++ tests/data/jsonchecker/fail23.json
  126. @@ -0,0 +1,1 @@
  127. +["Bad value", truth]
  128.  
  129. ADDED tests/data/jsonchecker/fail24.json
  130. Index: tests/data/jsonchecker/fail24.json
  131. ==================================================================
  132. --- tests/data/jsonchecker/fail24.json
  133. +++ tests/data/jsonchecker/fail24.json
  134. @@ -0,0 +1,1 @@
  135. +['single quote']
  136.  
  137. ADDED tests/data/jsonchecker/fail25.json
  138. Index: tests/data/jsonchecker/fail25.json
  139. ==================================================================
  140. --- tests/data/jsonchecker/fail25.json
  141. +++ tests/data/jsonchecker/fail25.json
  142. @@ -0,0 +1,1 @@
  143. +[" tab character in string "]
  144.  
  145. ADDED tests/data/jsonchecker/fail26.json
  146. Index: tests/data/jsonchecker/fail26.json
  147. ==================================================================
  148. --- tests/data/jsonchecker/fail26.json
  149. +++ tests/data/jsonchecker/fail26.json
  150. @@ -0,0 +1,1 @@
  151. +["tab\ character\ in\ string\ "]
  152.  
  153. ADDED tests/data/jsonchecker/fail27.json
  154. Index: tests/data/jsonchecker/fail27.json
  155. ==================================================================
  156. --- tests/data/jsonchecker/fail27.json
  157. +++ tests/data/jsonchecker/fail27.json
  158. @@ -0,0 +1,2 @@
  159. +["line
  160. +break"]
  161.  
  162. ADDED tests/data/jsonchecker/fail28.json
  163. Index: tests/data/jsonchecker/fail28.json
  164. ==================================================================
  165. --- tests/data/jsonchecker/fail28.json
  166. +++ tests/data/jsonchecker/fail28.json
  167. @@ -0,0 +1,2 @@
  168. +["line\
  169. +break"]
  170.  
  171. ADDED tests/data/jsonchecker/fail29.json
  172. Index: tests/data/jsonchecker/fail29.json
  173. ==================================================================
  174. --- tests/data/jsonchecker/fail29.json
  175. +++ tests/data/jsonchecker/fail29.json
  176. @@ -0,0 +1,1 @@
  177. +[0e]
  178.  
  179. ADDED tests/data/jsonchecker/fail3.json
  180. Index: tests/data/jsonchecker/fail3.json
  181. ==================================================================
  182. --- tests/data/jsonchecker/fail3.json
  183. +++ tests/data/jsonchecker/fail3.json
  184. @@ -0,0 +1,1 @@
  185. +{unquoted_key: "keys must be quoted"}
  186.  
  187. ADDED tests/data/jsonchecker/fail30.json
  188. Index: tests/data/jsonchecker/fail30.json
  189. ==================================================================
  190. --- tests/data/jsonchecker/fail30.json
  191. +++ tests/data/jsonchecker/fail30.json
  192. @@ -0,0 +1,1 @@
  193. +[0e+]
  194.  
  195. ADDED tests/data/jsonchecker/fail31.json
  196. Index: tests/data/jsonchecker/fail31.json
  197. ==================================================================
  198. --- tests/data/jsonchecker/fail31.json
  199. +++ tests/data/jsonchecker/fail31.json
  200. @@ -0,0 +1,1 @@
  201. +[0e+-1]
  202.  
  203. ADDED tests/data/jsonchecker/fail32.json
  204. Index: tests/data/jsonchecker/fail32.json
  205. ==================================================================
  206. --- tests/data/jsonchecker/fail32.json
  207. +++ tests/data/jsonchecker/fail32.json
  208. @@ -0,0 +1,1 @@
  209. +{"Comma instead if closing brace": true,
  210.  
  211. ADDED tests/data/jsonchecker/fail33.json
  212. Index: tests/data/jsonchecker/fail33.json
  213. ==================================================================
  214. --- tests/data/jsonchecker/fail33.json
  215. +++ tests/data/jsonchecker/fail33.json
  216. @@ -0,0 +1,1 @@
  217. +["mismatch"}
  218.  
  219. ADDED tests/data/jsonchecker/fail4.json
  220. Index: tests/data/jsonchecker/fail4.json
  221. ==================================================================
  222. --- tests/data/jsonchecker/fail4.json
  223. +++ tests/data/jsonchecker/fail4.json
  224. @@ -0,0 +1,1 @@
  225. +["extra comma",]
  226.  
  227. ADDED tests/data/jsonchecker/fail5.json
  228. Index: tests/data/jsonchecker/fail5.json
  229. ==================================================================
  230. --- tests/data/jsonchecker/fail5.json
  231. +++ tests/data/jsonchecker/fail5.json
  232. @@ -0,0 +1,1 @@
  233. +["double extra comma",,]
  234.  
  235. ADDED tests/data/jsonchecker/fail6.json
  236. Index: tests/data/jsonchecker/fail6.json
  237. ==================================================================
  238. --- tests/data/jsonchecker/fail6.json
  239. +++ tests/data/jsonchecker/fail6.json
  240. @@ -0,0 +1,1 @@
  241. +[ , "<-- missing value"]
  242.  
  243. ADDED tests/data/jsonchecker/fail7.json
  244. Index: tests/data/jsonchecker/fail7.json
  245. ==================================================================
  246. --- tests/data/jsonchecker/fail7.json
  247. +++ tests/data/jsonchecker/fail7.json
  248. @@ -0,0 +1,1 @@
  249. +["Comma after the close"],
  250.  
  251. ADDED tests/data/jsonchecker/fail8.json
  252. Index: tests/data/jsonchecker/fail8.json
  253. ==================================================================
  254. --- tests/data/jsonchecker/fail8.json
  255. +++ tests/data/jsonchecker/fail8.json
  256. @@ -0,0 +1,1 @@
  257. +["Extra close"]]
  258.  
  259. ADDED tests/data/jsonchecker/fail9.json
  260. Index: tests/data/jsonchecker/fail9.json
  261. ==================================================================
  262. --- tests/data/jsonchecker/fail9.json
  263. +++ tests/data/jsonchecker/fail9.json
  264. @@ -0,0 +1,1 @@
  265. +{"Extra comma": true,}
  266.  
  267. ADDED tests/data/jsonchecker/pass1.json
  268. Index: tests/data/jsonchecker/pass1.json
  269. ==================================================================
  270. --- tests/data/jsonchecker/pass1.json
  271. +++ tests/data/jsonchecker/pass1.json
  272. @@ -0,0 +1,58 @@
  273. +[
  274. + "JSON Test Pattern pass1",
  275. + {"object with 1 member":["array with 1 element"]},
  276. + {},
  277. + [],
  278. + -42,
  279. + true,
  280. + false,
  281. + null,
  282. + {
  283. + "integer": 1234567890,
  284. + "real": -9876.543210,
  285. + "e": 0.123456789e-12,
  286. + "E": 1.234567890E+34,
  287. + "": 23456789012E66,
  288. + "zero": 0,
  289. + "one": 1,
  290. + "space": " ",
  291. + "quote": "\"",
  292. + "backslash": "\\",
  293. + "controls": "\b\f\n\r\t",
  294. + "slash": "/ & \/",
  295. + "alpha": "abcdefghijklmnopqrstuvwyz",
  296. + "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
  297. + "digit": "0123456789",
  298. + "0123456789": "digit",
  299. + "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
  300. + "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
  301. + "true": true,
  302. + "false": false,
  303. + "null": null,
  304. + "array":[ ],
  305. + "object":{ },
  306. + "address": "50 St. James Street",
  307. + "url": "http://www.JSON.org/",
  308. + "comment": "// /* <!-- --",
  309. + "# -- --> */": " ",
  310. + " s p a c e d " :[1,2 , 3
  311. +
  312. +,
  313. +
  314. +4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
  315. + "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
  316. + "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
  317. + "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
  318. +: "A key can be any string"
  319. + },
  320. + 0.5 ,98.6
  321. +,
  322. +99.44
  323. +,
  324. +
  325. +1066,
  326. +1e1,
  327. +0.1e1,
  328. +1e-1,
  329. +1e00,2e+00,2e-00
  330. +,"rosebud"]
  331.  
  332. ADDED tests/data/jsonchecker/pass2.json
  333. Index: tests/data/jsonchecker/pass2.json
  334. ==================================================================
  335. --- tests/data/jsonchecker/pass2.json
  336. +++ tests/data/jsonchecker/pass2.json
  337. @@ -0,0 +1,1 @@
  338. +[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
  339.  
  340. ADDED tests/data/jsonchecker/pass3.json
  341. Index: tests/data/jsonchecker/pass3.json
  342. ==================================================================
  343. --- tests/data/jsonchecker/pass3.json
  344. +++ tests/data/jsonchecker/pass3.json
  345. @@ -0,0 +1,6 @@
  346. +{
  347. + "JSON Test Pattern pass3": {
  348. + "The outermost value": "must be an object or array.",
  349. + "In this test": "It is an object."
  350. + }
  351. +}
  352.  
  353. ADDED tests/jsonchecker.test
  354. Index: tests/jsonchecker.test
  355. ==================================================================
  356. --- tests/jsonchecker.test
  357. +++ tests/jsonchecker.test
  358. @@ -0,0 +1,45 @@
  359. +#
  360. +# http://www.json.org/JSON_checker/
  361. +# http://www.json.org/JSON_checker/test.zip
  362. +#
  363. +
  364. +source [file join [file dir [info script]] loadtdom.tcl]
  365. +
  366. +set datadir [file join tests data [lindex [split [file tail [info script]] "."] 0]]
  367. +
  368. +set counter 1
  369. +
  370. +foreach pass [lsort [glob -dir $datadir pass*]] {
  371. + set fh [open $pass r]
  372. + set json [read $fh]
  373. + test jsonchecker-$counter "Rountrip: $pass" -body {
  374. + set doc [dom parse -json $json]
  375. + set out [$doc asJSON]
  376. + $doc delete
  377. + set out
  378. + } -result $json -cleanup {
  379. + catch {close $fh}
  380. + unset -nocomplain fh
  381. + unset -nocomplain json
  382. + incr counter
  383. + }
  384. +}
  385. +
  386. +foreach fail [lsort [glob -dir $datadir fail*]] {
  387. + test jsonchecker-$counter "Syntax fail: $fail" -setup {
  388. + set fh [open $fail r]
  389. + set json [read $fh]
  390. + } -body {
  391. + dom parse -json $json
  392. + } -result {error "JSON syntax error" at position*} -match glob -returnCodes 1 -cleanup {
  393. + catch {close $fh}
  394. + unset -nocomplain fh
  395. + unset -nocomplain json
  396. + incr counter
  397. + }
  398. +}
  399. +
  400. +
  401. +
  402. +
  403. +
  404.  
  405.