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
|
#
# chartype.test
#
# Tests for the ctype command.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies. Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose. It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: chartype.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $
#------------------------------------------------------------------------------
#
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
# Use format to convert number to character.
proc numToChar num {
return [format %c $num]
}
# Use scan to convert character to number.
proc charToNum str {
scan $str %c num
return $num
}
test chartype-1.1 {ctype tests} {
ctype digit 01234567
} 1
test chartype-1.2 {ctype tests} {
ctype digit abc123cd
} 0
test chartype-1.3 {ctype tests} {
ctype xdigit 01234567abcdefABCDEF
} 1
test chartype-1.4 {ctype tests} {
ctype xdigit XMc123cd
} 0
test chartype-1.4.1 {ctype tests} {
list [ctype -failindex failIdx xdigit XMc123cd] $failIdx
} {0 0}
test chartype-1.5 {ctype tests} {
ctype lower abcdefgh
} 1
test chartype-1.6 {ctype tests} {
ctype lower abcDeFgh
} 0
test chartype-1.6.1 {ctype tests} {
list [ctype -failindex failIdx lower abcDeFgh] $failIdx
} {0 3}
test chartype-1.7 {ctype tests} {
ctype upper ABCDEFGH
} 1
test chartype-1.8 {ctype tests} {
ctype upper abcDeFgh
} 0
test chartype-1.8.1 {ctype tests} {
list [ctype -failindex failIdx upper DabcDeFgh] $failIdx
} {0 1}
test chartype-1.9 {ctype tests} {
ctype alpha abcdXYZ
} 1
test chartype-1.10 {ctype tests} {
ctype alpha abc123cd
} 0
test chartype-1.10.1 {ctype tests} {
list [ctype -failindex failIdx alpha abc123cd] $failIdx
} {0 3}
test chartype-1.11 {ctype tests} {
ctype alnum 0123ABC7
} 1
test chartype-1.12 {ctype tests} {
ctype alnum ab.%23cd
} 0
test chartype-1.12.1 {ctype tests} {
list [ctype -failindex failIdx alnum ab.%23cd] $failIdx
} {0 2}
test chartype-1.13 {ctype tests} {
ctype space " \t\n "
} 1
test chartype-1.14 {ctype tests} {
ctype space "ab \t z"
} 0
test chartype-1.14.1 {ctype tests} {
list [ctype -failindex failIdx space "ab \t z"] $failIdx
} {0 0}
test chartype-1.15 {ctype tests} {
ctype cntrl "[ctype char 7][ctype char 15][ctype char 20]"
} 1
test chartype-1.16 {ctype tests} {
ctype cntrl "[ctype char 7]abcd"
} 0
test chartype-1.16,1 {ctype tests} {
list [ctype -failindex failIdx cntrl "[ctype char 7]abcd"] $failIdx
} {0 1}
test chartype-1.17 {ctype tests} {
ctype punct ".,:;"
} 1
test chartype-1.18 {ctype tests} {
ctype punct ".,:;ab"
} 0
test chartype-1.18.1 {ctype tests} {
list [ctype -failindex failIdx punct ".,:;ab"] $failIdx
} {0 4}
test chartype-1.19 {ctype tests} {
ctype print "01 :;.567"
} 1
test chartype-1.20 {ctype tests} {
ctype print "[ctype char 7][ctype char 15]abc"
} 0
test chartype-1.20.1 {ctype tests} {
list [ctype -failindex failIdx print "[ctype char 7][ctype char 15]abc"] $failIdx
} {0 0}
test chartype-1.21 {ctype tests} {
ctype graph "ab.zxy"
} 1
test chartype-1.22 {ctype tests} {
ctype graph "abc 3cd"
} 0
test chartype-1.22.1 {ctype tests} {
list [ctype -failindex failIdx graph "abc 3cd"] $failIdx
} {0 3}
test chartype-1.23 {ctype tests} {
ctype ascii 01234567
} 1
test chartype-1.24 {ctype tests} {
ctype ascii "[ctype char 220][ctype char 126]123cd"
} 0
test chartype-1.24.1 {ctype tests} {
list [ctype -failindex failIdx ascii "[ctype char 220][ctype char 126]123cd"] $failIdx
} {0 0}
test chartype-1.25 {ctype tests} {
list [catch {ctype ascii} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.25.1 {ctype tests} {
list [catch {ctype ascii string junk} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.25.2 {ctype tests} {
list [catch {ctype -failindex ascii} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.25.3 {ctype tests} {
list [catch {ctype -failindex failIdx ascii} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.25.4 {ctype tests} {
list [catch {ctype -failindex failIdx ascii string junk} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.26 {ctype tests} {
list [catch {ctype ascbb foo} msg] $msg
} {1 {unrecognized class specification: "ascbb", expected one of: alnum, alpha, ascii, char, cntrl, digit, graph, lower, ord, print, punct, space, upper or xdigit}}
test chartype-1.27 {ctype char tests} {
ctype char 65
} [numToChar 65]
test chartype-1.28 {ctype char tests} {
ctype char 97
} [numToChar 97]
test chartype-1.29 {ctype char tests} {
ctype char 57
} [numToChar 57]
test chartype-1.30 {ctype char tests} {
ctype char 35
} [numToChar 35]
test chartype-1.32 {ctype ord tests} {
ctype ord A
} [charToNum A]
test chartype-1.33 {ctype ord tests} {
ctype ord a
} [charToNum a]
test chartype-1.34 {ctype ord tests} {
ctype ord 9
} [charToNum 9]
test chartype-1.35 {ctype ord tests} {
ctype ord "#"
} [charToNum \#]
test chartype-1.36 {ctype ord tests} {
list [catch {ctype ord} msg] $msg
} {1 {wrong # args: ctype ?-failindex var? class string}}
test chartype-1.37 {ctype ord tests} {
ctype ord ""
} {0}
test chartype-1.38 {ctype ord tests} {
ctype ord \377
} [charToNum \377]
test chartype-1.39 {ctype ord tests} {
ctype ord \277
} [charToNum \277]
test chartype-1.40 {ctype ord tests} {
ctype char 255
} [numToChar 255]
test chartype-1.41 {ctype ord tests} {
ctype char 1722
} [numToChar 1722]
# cleanup
::tcltest::cleanupTests
return
|