File: json.testsuite

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (102 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- tcl -*-
# -------------------------------------------------------------------------
# Tests
# -------------------------------------------------------------------------

set i 0
foreach name [lsort -dict [array names JSON]] {
    test json-${impl}-1.[incr i] "test JSON $name" -body {
	transform [json::json2dict $JSON($name)] $name
    } -result [resultfor $name]
}

set i 0
foreach name [lsort -dict [array names JSON]] {
    test json-${impl}-7.[incr i] "validate JSON $name" -body {
        json::validate $JSON($name)
    } -result 1
}

set i 0
foreach name [lsort -dict [array names FAIL]] {
    test json-${impl}-8.[incr i] "test FAIL $name" -body {
	json::json2dict $FAIL($name)
    } -returnCodes error -result $ERR(${name}-${impl})
}

set i 0
foreach name [lsort -dict [array names FAIL]] {
    test json-${impl}-9.[incr i] "validate FAIL $name" -body {
        json::validate $FAIL($name)
    } -result 0
}

# -------------------------------------------------------------------------
# More Tests - list2json, string2json
# TODO: dict2json
# -------------------------------------------------------------------------

test json-${impl}-2.0 {list2json} -body {
    json::list2json {{"a"} {"b"} {"c"}}
} -result {["a","b","c"]}

test json-${impl}-2.1 {string2json} -body {
    json::string2json a
} -result {"a"}

# -------------------------------------------------------------------------
# many-json2dict
# -------------------------------------------------------------------------

test json-${impl}-3.0 {many-json2dict, wrong args, not enough} -body {
    json::many-json2dict
} -returnCodes error -match glob -result {wrong # args: should be "*json::many[-_]json2dict* jsonText ?max?"}

test json-${impl}-3.1 {many-json2dict, wrong args, too many} -body {
    json::many-json2dict J M X
} -returnCodes error -match glob -result {wrong # args: should be "*json::many[-_]json2dict* jsonText ?max?"}

test json-${impl}-3.2 {many-json2dict, bad limit, zero} -body {
    json::many-json2dict {[]} 0
} -returnCodes error -result {Bad limit 0 of json entities to extract.}

set i 0
foreach first [lsort -dict [array names JSON]] {
    foreach second [lsort -dict [array names JSON]] {
        set    input $JSON($first)
        append input " " $JSON($second)

        set     output {}
        lappend output [resultfor $first]
        lappend output [resultfor $second]

        test json-${impl}-4.[incr i] "many-json2dict: $first/$second, all" -body {
            transform* [json::many-json2dict $input] $first $second
        } -result $output
    }
}

set i 0
foreach first [lsort -dict [array names JSON]] {
    foreach second [lsort -dict [array names JSON]] {
        set    input $JSON($first)
        append input " " $JSON($second)

        set     output {}
        lappend output [resultfor $first]

        test json-${impl}-5.[incr i] "many-json2dict: $first/$second, first only" -body {
            transform* [json::many-json2dict $input 1] $first
        } -result $output
    }
}

set i 0
foreach first [lsort -dict [array names JSON]] {
    set input $JSON($first)
    test json-${impl}-6.[incr i] "many-json2dict, bad limit, 3 over 1" -body {
        json::many-json2dict $input 3
    } -returnCodes error -result {Bad limit 3 of json entities to extract, found only 1.}
}

# -------------------------------------------------------------------------