Posted to tcl by mr_calvin at Fri Jul 14 10:55:54 GMT 2017view raw
- ÿÿÿADDED tests/data/jsonchecker/fail1.json
- Index: tests/data/jsonchecker/fail1.json
- ==================================================================
- --- tests/data/jsonchecker/fail1.json
- +++ tests/data/jsonchecker/fail1.json
- @@ -0,0 +1,1 @@
- +"A JSON payload should be an object or array, not a string."
- ADDED tests/data/jsonchecker/fail10.json
- Index: tests/data/jsonchecker/fail10.json
- ==================================================================
- --- tests/data/jsonchecker/fail10.json
- +++ tests/data/jsonchecker/fail10.json
- @@ -0,0 +1,1 @@
- +{"Extra value after close": true} "misplaced quoted value"
- ADDED tests/data/jsonchecker/fail11.json
- Index: tests/data/jsonchecker/fail11.json
- ==================================================================
- --- tests/data/jsonchecker/fail11.json
- +++ tests/data/jsonchecker/fail11.json
- @@ -0,0 +1,1 @@
- +{"Illegal expression": 1 + 2}
- ADDED tests/data/jsonchecker/fail12.json
- Index: tests/data/jsonchecker/fail12.json
- ==================================================================
- --- tests/data/jsonchecker/fail12.json
- +++ tests/data/jsonchecker/fail12.json
- @@ -0,0 +1,1 @@
- +{"Illegal invocation": alert()}
- ADDED tests/data/jsonchecker/fail13.json
- Index: tests/data/jsonchecker/fail13.json
- ==================================================================
- --- tests/data/jsonchecker/fail13.json
- +++ tests/data/jsonchecker/fail13.json
- @@ -0,0 +1,1 @@
- +{"Numbers cannot have leading zeroes": 013}
- ADDED tests/data/jsonchecker/fail14.json
- Index: tests/data/jsonchecker/fail14.json
- ==================================================================
- --- tests/data/jsonchecker/fail14.json
- +++ tests/data/jsonchecker/fail14.json
- @@ -0,0 +1,1 @@
- +{"Numbers cannot be hex": 0x14}
- ADDED tests/data/jsonchecker/fail15.json
- Index: tests/data/jsonchecker/fail15.json
- ==================================================================
- --- tests/data/jsonchecker/fail15.json
- +++ tests/data/jsonchecker/fail15.json
- @@ -0,0 +1,1 @@
- +["Illegal backslash escape: \x15"]
- ADDED tests/data/jsonchecker/fail16.json
- Index: tests/data/jsonchecker/fail16.json
- ==================================================================
- --- tests/data/jsonchecker/fail16.json
- +++ tests/data/jsonchecker/fail16.json
- @@ -0,0 +1,1 @@
- +[\naked]
- ADDED tests/data/jsonchecker/fail17.json
- Index: tests/data/jsonchecker/fail17.json
- ==================================================================
- --- tests/data/jsonchecker/fail17.json
- +++ tests/data/jsonchecker/fail17.json
- @@ -0,0 +1,1 @@
- +["Illegal backslash escape: \017"]
- ADDED tests/data/jsonchecker/fail18.json
- Index: tests/data/jsonchecker/fail18.json
- ==================================================================
- --- tests/data/jsonchecker/fail18.json
- +++ tests/data/jsonchecker/fail18.json
- @@ -0,0 +1,1 @@
- +[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
- ADDED tests/data/jsonchecker/fail19.json
- Index: tests/data/jsonchecker/fail19.json
- ==================================================================
- --- tests/data/jsonchecker/fail19.json
- +++ tests/data/jsonchecker/fail19.json
- @@ -0,0 +1,1 @@
- +{"Missing colon" null}
- ADDED tests/data/jsonchecker/fail2.json
- Index: tests/data/jsonchecker/fail2.json
- ==================================================================
- --- tests/data/jsonchecker/fail2.json
- +++ tests/data/jsonchecker/fail2.json
- @@ -0,0 +1,1 @@
- +["Unclosed array"
- ADDED tests/data/jsonchecker/fail20.json
- Index: tests/data/jsonchecker/fail20.json
- ==================================================================
- --- tests/data/jsonchecker/fail20.json
- +++ tests/data/jsonchecker/fail20.json
- @@ -0,0 +1,1 @@
- +{"Double colon":: null}
- ADDED tests/data/jsonchecker/fail21.json
- Index: tests/data/jsonchecker/fail21.json
- ==================================================================
- --- tests/data/jsonchecker/fail21.json
- +++ tests/data/jsonchecker/fail21.json
- @@ -0,0 +1,1 @@
- +{"Comma instead of colon", null}
- ADDED tests/data/jsonchecker/fail22.json
- Index: tests/data/jsonchecker/fail22.json
- ==================================================================
- --- tests/data/jsonchecker/fail22.json
- +++ tests/data/jsonchecker/fail22.json
- @@ -0,0 +1,1 @@
- +["Colon instead of comma": false]
- ADDED tests/data/jsonchecker/fail23.json
- Index: tests/data/jsonchecker/fail23.json
- ==================================================================
- --- tests/data/jsonchecker/fail23.json
- +++ tests/data/jsonchecker/fail23.json
- @@ -0,0 +1,1 @@
- +["Bad value", truth]
- ADDED tests/data/jsonchecker/fail24.json
- Index: tests/data/jsonchecker/fail24.json
- ==================================================================
- --- tests/data/jsonchecker/fail24.json
- +++ tests/data/jsonchecker/fail24.json
- @@ -0,0 +1,1 @@
- +['single quote']
- ADDED tests/data/jsonchecker/fail25.json
- Index: tests/data/jsonchecker/fail25.json
- ==================================================================
- --- tests/data/jsonchecker/fail25.json
- +++ tests/data/jsonchecker/fail25.json
- @@ -0,0 +1,1 @@
- +[" tab character in string "]
- ADDED tests/data/jsonchecker/fail26.json
- Index: tests/data/jsonchecker/fail26.json
- ==================================================================
- --- tests/data/jsonchecker/fail26.json
- +++ tests/data/jsonchecker/fail26.json
- @@ -0,0 +1,1 @@
- +["tab\ character\ in\ string\ "]
- ADDED tests/data/jsonchecker/fail27.json
- Index: tests/data/jsonchecker/fail27.json
- ==================================================================
- --- tests/data/jsonchecker/fail27.json
- +++ tests/data/jsonchecker/fail27.json
- @@ -0,0 +1,2 @@
- +["line
- +break"]
- ADDED tests/data/jsonchecker/fail28.json
- Index: tests/data/jsonchecker/fail28.json
- ==================================================================
- --- tests/data/jsonchecker/fail28.json
- +++ tests/data/jsonchecker/fail28.json
- @@ -0,0 +1,2 @@
- +["line\
- +break"]
- ADDED tests/data/jsonchecker/fail29.json
- Index: tests/data/jsonchecker/fail29.json
- ==================================================================
- --- tests/data/jsonchecker/fail29.json
- +++ tests/data/jsonchecker/fail29.json
- @@ -0,0 +1,1 @@
- +[0e]
- ADDED tests/data/jsonchecker/fail3.json
- Index: tests/data/jsonchecker/fail3.json
- ==================================================================
- --- tests/data/jsonchecker/fail3.json
- +++ tests/data/jsonchecker/fail3.json
- @@ -0,0 +1,1 @@
- +{unquoted_key: "keys must be quoted"}
- ADDED tests/data/jsonchecker/fail30.json
- Index: tests/data/jsonchecker/fail30.json
- ==================================================================
- --- tests/data/jsonchecker/fail30.json
- +++ tests/data/jsonchecker/fail30.json
- @@ -0,0 +1,1 @@
- +[0e+]
- ADDED tests/data/jsonchecker/fail31.json
- Index: tests/data/jsonchecker/fail31.json
- ==================================================================
- --- tests/data/jsonchecker/fail31.json
- +++ tests/data/jsonchecker/fail31.json
- @@ -0,0 +1,1 @@
- +[0e+-1]
- ADDED tests/data/jsonchecker/fail32.json
- Index: tests/data/jsonchecker/fail32.json
- ==================================================================
- --- tests/data/jsonchecker/fail32.json
- +++ tests/data/jsonchecker/fail32.json
- @@ -0,0 +1,1 @@
- +{"Comma instead if closing brace": true,
- ADDED tests/data/jsonchecker/fail33.json
- Index: tests/data/jsonchecker/fail33.json
- ==================================================================
- --- tests/data/jsonchecker/fail33.json
- +++ tests/data/jsonchecker/fail33.json
- @@ -0,0 +1,1 @@
- +["mismatch"}
- ADDED tests/data/jsonchecker/fail4.json
- Index: tests/data/jsonchecker/fail4.json
- ==================================================================
- --- tests/data/jsonchecker/fail4.json
- +++ tests/data/jsonchecker/fail4.json
- @@ -0,0 +1,1 @@
- +["extra comma",]
- ADDED tests/data/jsonchecker/fail5.json
- Index: tests/data/jsonchecker/fail5.json
- ==================================================================
- --- tests/data/jsonchecker/fail5.json
- +++ tests/data/jsonchecker/fail5.json
- @@ -0,0 +1,1 @@
- +["double extra comma",,]
- ADDED tests/data/jsonchecker/fail6.json
- Index: tests/data/jsonchecker/fail6.json
- ==================================================================
- --- tests/data/jsonchecker/fail6.json
- +++ tests/data/jsonchecker/fail6.json
- @@ -0,0 +1,1 @@
- +[ , "<-- missing value"]
- ADDED tests/data/jsonchecker/fail7.json
- Index: tests/data/jsonchecker/fail7.json
- ==================================================================
- --- tests/data/jsonchecker/fail7.json
- +++ tests/data/jsonchecker/fail7.json
- @@ -0,0 +1,1 @@
- +["Comma after the close"],
- ADDED tests/data/jsonchecker/fail8.json
- Index: tests/data/jsonchecker/fail8.json
- ==================================================================
- --- tests/data/jsonchecker/fail8.json
- +++ tests/data/jsonchecker/fail8.json
- @@ -0,0 +1,1 @@
- +["Extra close"]]
- ADDED tests/data/jsonchecker/fail9.json
- Index: tests/data/jsonchecker/fail9.json
- ==================================================================
- --- tests/data/jsonchecker/fail9.json
- +++ tests/data/jsonchecker/fail9.json
- @@ -0,0 +1,1 @@
- +{"Extra comma": true,}
- ADDED tests/data/jsonchecker/pass1.json
- Index: tests/data/jsonchecker/pass1.json
- ==================================================================
- --- tests/data/jsonchecker/pass1.json
- +++ tests/data/jsonchecker/pass1.json
- @@ -0,0 +1,58 @@
- +[
- + "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"]
- ADDED tests/data/jsonchecker/pass2.json
- Index: tests/data/jsonchecker/pass2.json
- ==================================================================
- --- tests/data/jsonchecker/pass2.json
- +++ tests/data/jsonchecker/pass2.json
- @@ -0,0 +1,1 @@
- +[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
- ADDED tests/data/jsonchecker/pass3.json
- Index: tests/data/jsonchecker/pass3.json
- ==================================================================
- --- tests/data/jsonchecker/pass3.json
- +++ tests/data/jsonchecker/pass3.json
- @@ -0,0 +1,6 @@
- +{
- + "JSON Test Pattern pass3": {
- + "The outermost value": "must be an object or array.",
- + "In this test": "It is an object."
- + }
- +}
- ADDED tests/jsonchecker.test
- Index: tests/jsonchecker.test
- ==================================================================
- --- tests/jsonchecker.test
- +++ tests/jsonchecker.test
- @@ -0,0 +1,45 @@
- +#
- +# http://www.json.org/JSON_checker/
- +# http://www.json.org/JSON_checker/test.zip
- +#
- +
- +source [file join [file dir [info script]] loadtdom.tcl]
- +
- +set datadir [file join tests data [lindex [split [file tail [info script]] "."] 0]]
- +
- +set counter 1
- +
- +foreach pass [lsort [glob -dir $datadir pass*]] {
- + set fh [open $pass r]
- + set json [read $fh]
- + test jsonchecker-$counter "Rountrip: $pass" -body {
- + set doc [dom parse -json $json]
- + set out [$doc asJSON]
- + $doc delete
- + set out
- + } -result $json -cleanup {
- + catch {close $fh}
- + unset -nocomplain fh
- + unset -nocomplain json
- + incr counter
- + }
- +}
- +
- +foreach fail [lsort [glob -dir $datadir fail*]] {
- + test jsonchecker-$counter "Syntax fail: $fail" -setup {
- + set fh [open $fail r]
- + set json [read $fh]
- + } -body {
- + dom parse -json $json
- + } -result {error "JSON syntax error" at position*} -match glob -returnCodes 1 -cleanup {
- + catch {close $fh}
- + unset -nocomplain fh
- + unset -nocomplain json
- + incr counter
- + }
- +}
- +
- +
- +
- +
- +