-
Notifications
You must be signed in to change notification settings - Fork 12
/
boolean.test
117 lines (112 loc) · 3.21 KB
/
boolean.test
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
if {"::tcltest" ni [namespace children]} {
package require tcltest
namespace import ::tcltest::*
}
package require rl_json
test boolean-1.1 {Create a json boolean: 1} -body { #<<<
json boolean 1
} -result true
#>>>
test boolean-1.2 {Create a json boolean: 0} -body { #<<<
json boolean 0
} -result false
#>>>
test boolean-1.3 {Create a json boolean: truthy string: true} -body { #<<<
json boolean true
} -result true
#>>>
test boolean-1.4 {Create a json boolean: truthy string: t} -body { #<<<
json boolean t
} -result true
#>>>
test boolean-1.5 {Create a json boolean: truthy string: yes} -body { #<<<
json boolean yes
} -result true
#>>>
test boolean-1.6 {Create a json boolean: truthy string: y} -body { #<<<
json boolean y
} -result true
#>>>
test boolean-1.7 {Create a json boolean: truthy string: on} -body { #<<<
json boolean on
} -result true
#>>>
test boolean-1.8 {Create a json boolean: truthy string: o (ambiguous prefix)} -body { #<<<
json boolean o
} -returnCodes error -result {expected boolean value but got "o"}
#>>>
test boolean-1.9 {Create a json boolean: truthy number: 42} -body { #<<<
json boolean 42
} -result true
#>>>
test boolean-1.10 {Create a json boolean: truthy number: 42.5} -body { #<<<
json boolean 42.5
} -result true
#>>>
test boolean-1.11 {Create a json boolean: truthy number: 1e6} -body { #<<<
json boolean 1e6
} -result true
#>>>
test boolean-1.12 {Create a json boolean: truthy number: positive bignum} -body { #<<<
json boolean [expr {2**1000-1}]
} -result true
#>>>
test boolean-1.13 {Create a json boolean: truthy number: -42} -body { #<<<
json boolean -42
} -result true
#>>>
test boolean-1.14 {Create a json boolean: truthy number: -42.5} -body { #<<<
json boolean -42.5
} -result true
#>>>
test boolean-1.15 {Create a json boolean: truthy number: -1e6} -body { #<<<
json boolean -1e6
} -result true
#>>>
test boolean-1.16 {Create a json boolean: truthy number: negative bignum} -body { #<<<
json boolean [expr {-1*(2**1000-1)}]
} -result true
#>>>
test boolean-1.17 {Create a json boolean: json boolean true} -body { #<<<
json boolean [json boolean 1]
} -result true
#>>>
test boolean-1.18 {Create a json boolean: json boolean false} -body { #<<<
json boolean [json boolean 0]
} -result false
#>>>
test boolean-2.1 {Too few args} -body { #<<<
set code [catch {
json boolean
} r o]
list $code $r [dict get $o -errorcode]
} -result {1 {wrong # args: should be "*boolean value"} {TCL WRONGARGS}} -match glob
#>>>
test boolean-2.2 {Too many args} -body { #<<<
set code [catch {
json boolean foo bar
} r o]
list $code $r [dict get $o -errorcode]
} -result {1 {wrong # args: should be "*boolean value"} {TCL WRONGARGS}} -match glob
#>>>
test boolean-2.3 {Empty string} -body { #<<<
set code [catch {
json boolean ""
} r o]
list $code $r [dict get $o -errorcode]
} -result {1 {expected boolean value but got ""} {TCL VALUE NUMBER}}
#>>>
test boolean-2.4 {Non-truthy string} -body { #<<<
set code [catch {
json boolean maybe
} r o]
list $code $r [dict get $o -errorcode]
} -result {1 {expected boolean value but got "maybe"} {TCL VALUE NUMBER}}
#>>>
::tcltest::cleanupTests
return
# Local Variables:
# mode: tcl
# tab-width: 4
# End:
# vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4