-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.test
267 lines (235 loc) · 6.45 KB
/
check.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package require tcltest
eval ::tcltest::configure $argv
package require qcode
namespace import qc::*
namespace eval ::qcode::test {
namespace import ::tcltest::*
test check-1.0 {check INT castable success} -setup {
set qty 1.2
} -body {
qc::check qty INT
} -cleanup {
unset qty
} -result true
test check-1.0a {check INT castable success value} -setup {
set qty 1.2
qc::check qty INT
} -body {
set qty
} -cleanup {
unset qty
} -result 1
test check-1.01 {check INT false} -setup {
set qty "Im a string"
} -body {
qc::check qty INT
} -cleanup {
unset qty
} -returnCodes 1 -result "\"Im a string\" is not a valid integer for qty"
test check-1.02 {check INT simple} -setup {
set qty 99
} -body {
qc::check qty INT
} -cleanup {
unset qty
} -result true
test check-1.03 {check INTEGER simple} -setup {
set qty 99
} -body {
qc::check qty INTEGER
} -cleanup {
unset qty
} -result true
test check-1.04 {check BOOLEAN yes} -setup {
set bool yes
} -body {
qc::check bool BOOLEAN
} -cleanup {
unset bool
} -result true
test check-1.05 {check BOOLEAN no} -setup {
set bool no
} -body {
qc::check bool BOOLEAN
} -cleanup {
unset bool
} -result true
test check-1.06 {check BOOLEAN number} -setup {
set bool 1
} -body {
qc::check bool BOOLEAN
} -cleanup {
unset bool
} -result true
test check-1.07 {check BOOLEAN true} -setup {
set bool true
} -body {
qc::check bool BOOLEAN
} -cleanup {
unset bool
} -result true
test check-1.08 {check BOOLEAN negative custom} -setup {
set bool -1
} -body {
qc::check bool BOOLEAN "This is a custom msg"
} -cleanup {
unset bool
} -returnCodes 1 -result "This is a custom msg"
test check-1.09 {check STRING postive} -setup {
set str "A string"
} -body {
qc::check str STRING 30
} -cleanup {
unset str
} -result true
test check-1.09 {check STRING postive} -setup {
set str "A string"
} -body {
qc::check str STRING 30
} -cleanup {
unset str
} -result true
test check-1.10 {check STRING too long} -setup {
set str "A slightly too long string"
} -body {
qc::check str STRING 20
} -cleanup {
unset str
} -returnCodes 1 -result "\"A slightly too long string\" is not a valid varchar for str"
test check-1.11 {check STRING null} -setup {
set str ""
} -body {
qc::check str STRING 20
} -cleanup {
unset str
} -result true
test check-1.12 {check STRING not null} -setup {
set str ""
} -body {
qc::check str STRING 20 NOT NULL
} -cleanup {
unset str
} -returnCodes 1 -result "str is empty"
test check-1.13 {check DECIMAL} -setup {
set dec -1.2
} -body {
qc::check dec DECIMAL
} -cleanup {
unset dec
} -result true
test check-1.14 {check DECIMAL POS fail} -setup {
set dec -1.2
} -body {
qc::check dec DECIMAL POS
} -cleanup {
unset dec
} -returnCodes 1 -result "\"-1.2\" is not a valid pos for dec"
test check-1.15 {check DECIMAL POS success} -setup {
set dec 1.2
} -body {
qc::check dec DECIMAL POS
} -cleanup {
unset dec
} -result true
test check-1.16 {check DATE castable success} -setup {
set date "20/7/81"
} -body {
qc::check date DATE
} -cleanup {
unset date
} -result true
test check-1.17 {check DATE castable success value} -setup {
set date "20/7/81"
qc::check date DATE
} -body {
set date
} -cleanup {
unset date
} -result 1981-07-20
test check-1.18 {check DATE success} -setup {
set date "2012-08-01"
} -body {
qc::check date DATE
} -cleanup {
unset date
} -result true
test check-1.19 {check NOT HTML success} -setup {
set text "Nothing to see here."
} -body {
qc::check text NOT HTML
} -cleanup {
unset text
} -result true
test check-1.20 {check NOT HTML fail} -setup {
set text "Nothing to <a href=http://hack.me>see</a> here."
} -body {
qc::check text NOT HTML
} -cleanup {
unset text
} -returnCodes 1 -result "\"Nothing to <a href=http://hack.me>see</a> here.\" contains HTML which is not allowed for text"
test check-1.21 {check NOT CREDITCARDS success} -setup {
set text "Just a number ( 4123123112311231 ) that looks like a CC number but isnt."
} -body {
qc::check text NOT CREDITCARDS
} -cleanup {
unset text
} -result true
test check-1.22 {check NOT CREDITCARDS failure} -setup {
set text "This is a valid CC number 4111111111111111 "
} -body {
qc::check text NOT CREDITCARDS
} -cleanup {
unset text
} -returnCodes 1 -result "\"This is a valid CC number 4111111111111111 \" contains a creditcard number which is not allowed for text"
test check-1.23 {check PRICE success} -setup {
set price "1.21"
} -body {
qc::check price PRICE
} -cleanup {
unset price
} -result true
test checks-1.00 {checks success} -setup {
set price "1.21"
set text "This is a string"
set dec 1.2
set cc 4111111111111111
set html "<p>Hello</p>"
} -body {
qc::checks {
price PRICE
text STRING 30 NOT NULL
dec DECIMAL
cc CREDITCARD
html HTML
}
} -cleanup {
unset price
unset text
unset dec
unset cc
unset html
} -result ""
test checks-1.01 {checks failure} -setup {
set price "1.21"
set text "This is a string"
set dec 1.2
set cc 999
set html "<p>Hello</p>"
} -body {
qc::checks {
price PRICE
text STRING 30 NOT NULL
dec DECIMAL
cc CREDITCARD
html HTML
}
} -cleanup {
unset price
unset text
unset dec
unset cc
unset html
} -returnCodes 1 -match glob -result "*\"999\" is not a valid creditcard for cc*"
cleanupTests
}
namespace delete ::qcode::test