| 1 |
/* |
| 2 |
* @progname st_string.li |
| 3 |
* @version 1.2 of 2005-01-12 |
| 4 |
* @author Perry Rapp |
| 5 |
* @category self-test |
| 6 |
* @output none |
| 7 |
* @description validate string functions |
| 8 |
*/ |
| 9 |
|
| 10 |
char_encoding("ASCII") |
| 11 |
|
| 12 |
require("lifelines-reports.version:1.3") |
| 13 |
option("explicitvars") /* Disallow use of undefined variables */ |
| 14 |
include("st_aux") |
| 15 |
|
| 16 |
global(undef) /* variable with no set value, used in string tests */ |
| 17 |
|
| 18 |
/* entry point in case not invoked via st_all.ll */ |
| 19 |
proc main() |
| 20 |
{ |
| 21 |
call testStrings() |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
test some string functions against defined & undefined strings |
| 26 |
*/ |
| 27 |
proc testStrings() |
| 28 |
{ |
| 29 |
call initSubsection() |
| 30 |
|
| 31 |
set(str,"hey") |
| 32 |
set(str2,upper(str)) |
| 33 |
if (ne(str2,"HEY")) { |
| 34 |
call reportfail("upper FAILED") |
| 35 |
} |
| 36 |
else { incr(testok) } |
| 37 |
|
| 38 |
set(str4,capitalize(str)) |
| 39 |
if (ne(str4,"Hey")) { |
| 40 |
call reportfail("capitalize FAILED") |
| 41 |
} |
| 42 |
else { incr(testok) } |
| 43 |
|
| 44 |
set(str4,titlecase(str)) |
| 45 |
if (ne(str4,"Hey")) { |
| 46 |
call reportfail("titlecase FAILED") |
| 47 |
} |
| 48 |
else { incr(testok) } |
| 49 |
|
| 50 |
set(str6,concat(str2,str4)) |
| 51 |
if (ne(str6,"HEYHey")) { |
| 52 |
call reportfail("concat FAILED") |
| 53 |
} |
| 54 |
else { incr(testok) } |
| 55 |
|
| 56 |
set(str3,upper(undef)) |
| 57 |
set(str5,capitalize(undef)) |
| 58 |
set(str5,titlecase(undef)) |
| 59 |
set(str7,concat(str3,str5)) |
| 60 |
if (ne(str7,"")) { |
| 61 |
call reportfail("concat FAILED on undefs") |
| 62 |
} |
| 63 |
else { incr(testok) } |
| 64 |
|
| 65 |
set(str7,strconcat(str3,str5)) |
| 66 |
if (ne(str7,"")) { |
| 67 |
call reportfail("strconcat FAILED on undefs") |
| 68 |
} |
| 69 |
else { incr(testok) } |
| 70 |
|
| 71 |
set(str8,lower(str4)) |
| 72 |
if (ne(str8,"hey")) { |
| 73 |
call reportfail("lower FAILED") |
| 74 |
} |
| 75 |
else { incr(testok) } |
| 76 |
|
| 77 |
set(str9,lower(undef)) |
| 78 |
if (ne(str9,undef)) { |
| 79 |
call reportfail("lower FAILED on undef") |
| 80 |
} |
| 81 |
else { incr(testok) } |
| 82 |
|
| 83 |
set(str10,alpha(3)) |
| 84 |
if(ne(str10,"c")) { |
| 85 |
call reportfail("alpha(3) FAILED") |
| 86 |
} |
| 87 |
else { incr(testok) } |
| 88 |
|
| 89 |
set(str10,roman(4)) |
| 90 |
if(ne(str10,"iv")) { |
| 91 |
call reportfail("roman(4) FAILED") |
| 92 |
} |
| 93 |
else { incr(testok) } |
| 94 |
|
| 95 |
set(str11,d(43)) |
| 96 |
if(ne(str11,"43")) { |
| 97 |
call reportfail("d(43) FAILED") |
| 98 |
} |
| 99 |
else { incr(testok) } |
| 100 |
|
| 101 |
set(str12,card(4)) |
| 102 |
if(ne(str12,"four")) { |
| 103 |
call reportfail("card(4) FAILED") |
| 104 |
} |
| 105 |
else { incr(testok) } |
| 106 |
|
| 107 |
set(str13,ord(5)) |
| 108 |
if(ne(str13,"fifth")) { |
| 109 |
call reportfail("ord(5) FAILED") |
| 110 |
} |
| 111 |
else { incr(testok) } |
| 112 |
|
| 113 |
/* 2003-08-06 - MTE - modified to ensure that titlecase() */ |
| 114 |
/* doesn't lowercase strings first */ |
| 115 |
set(str14,titlecase("big brown 1MEAN horse")) |
| 116 |
if(ne(str14,"Big Brown 1MEAN Horse")) { |
| 117 |
call reportfail("titlecase FAILED") |
| 118 |
} |
| 119 |
else { incr(testok) } |
| 120 |
|
| 121 |
/* 2003-08-06 - MTE - added to ensure that capitalize() */ |
| 122 |
/* doesn't lowercase strings first */ |
| 123 |
set(str15,capitalize("lower UPPER lower")) |
| 124 |
if(ne(str15,"Lower UPPER lower")) { |
| 125 |
call reportfail("capitalize FAILED") |
| 126 |
} |
| 127 |
else { incr(testok) } |
| 128 |
|
| 129 |
if (ge(strcmp("alpha","beta"),0)) { |
| 130 |
call reportfail("strcmp(alpha,beta) FAILED") |
| 131 |
} |
| 132 |
else { incr(testok) } |
| 133 |
|
| 134 |
if (le(strcmp("gamma","delta"),0)) { |
| 135 |
call reportfail("strcmp(gamma,delta) FAILED") |
| 136 |
} |
| 137 |
else { incr(testok) } |
| 138 |
|
| 139 |
if (ne(strcmp("zeta","zeta"),0)) { |
| 140 |
call reportfail("strcmp(zeta,zeta) FAILED") |
| 141 |
} |
| 142 |
else { incr(testok) } |
| 143 |
|
| 144 |
if (ne(strcmp(undef,""),0)) { |
| 145 |
call reportfail("strcmp(undef,) FAILED") |
| 146 |
} |
| 147 |
else { incr(testok) } |
| 148 |
|
| 149 |
if (ne(substring("considerable",2,4),"ons")) { |
| 150 |
call reportfail("substring(considerable,2,4) FAILED") |
| 151 |
} |
| 152 |
else { incr(testok) } |
| 153 |
|
| 154 |
if (ne(substring(undef,2,4),0)) { |
| 155 |
call reportfail("substring(undef,2,4) FAILED") |
| 156 |
} |
| 157 |
else { incr(testok) } |
| 158 |
|
| 159 |
if (ne(rjustify("hey",5), " hey")) { |
| 160 |
call reportfail("rjustify(hey,5) FAILED") |
| 161 |
} |
| 162 |
else { incr(testok) } |
| 163 |
|
| 164 |
if (ne(rjustify("heymon",5), "heymo")) { |
| 165 |
call reportfail("rjustify(heymon,5) FAILED") |
| 166 |
} |
| 167 |
else { incr(testok) } |
| 168 |
|
| 169 |
/* eqstr returns bool, which may be compared to 0 but no other number */ |
| 170 |
if (ne(eqstr("alpha","beta"),0)) { |
| 171 |
call reportfail("eqstr(alpha,beta) FAILED") |
| 172 |
} |
| 173 |
else { incr(testok) } |
| 174 |
|
| 175 |
if (not(eqstr("alpha","alpha"))) { |
| 176 |
call reportfail("eqstr(alpha,alpha) FAILED") |
| 177 |
} |
| 178 |
else { incr(testok) } |
| 179 |
|
| 180 |
if (ne(strtoint("4"), 4)) { |
| 181 |
call reportfail("strtoint(4) FAILED") |
| 182 |
} |
| 183 |
else { incr(testok) } |
| 184 |
|
| 185 |
if (ne(strsoundex("pat"),strsoundex("pet"))) { |
| 186 |
call reportfail("soundex(pat) FAILED") |
| 187 |
} |
| 188 |
else { incr(testok) } |
| 189 |
|
| 190 |
if (ne(strlen("pitch"),5)) { |
| 191 |
call reportfail("strlen(pitch) FAILED") |
| 192 |
} |
| 193 |
else { incr(testok) } |
| 194 |
|
| 195 |
set(str14,"the cat in the hat put the sack on the rat and the hat on the bat ") |
| 196 |
if (ne(index(str14,"at",1),6)) { |
| 197 |
call reportfail("index(str14,at,1) FAILED") |
| 198 |
} |
| 199 |
else { incr(testok) } |
| 200 |
|
| 201 |
if (ne(index(str14,"at",2),17)) |
| 202 |
{ |
| 203 |
call reportfail("index(str14,at,2) FAILED") |
| 204 |
} |
| 205 |
else { incr(testok) } |
| 206 |
|
| 207 |
if (ne(index(str14,"at",3),41)) |
| 208 |
{ |
| 209 |
call reportfail("index(str14,at,3) FAILED") |
| 210 |
} |
| 211 |
else { incr(testok) } |
| 212 |
|
| 213 |
if (ne(index(str14,"at",4),53)) |
| 214 |
{ |
| 215 |
call reportfail("index(str14,at,4) FAILED") |
| 216 |
} |
| 217 |
else { incr(testok) } |
| 218 |
|
| 219 |
if (ne(index(str14,"at",5),64)) |
| 220 |
{ |
| 221 |
call reportfail("index(str14,at,5) FAILED") |
| 222 |
} |
| 223 |
else { incr(testok) } |
| 224 |
|
| 225 |
if (ne(strlen(str14),66)) |
| 226 |
{ |
| 227 |
call reportfail("strlen(str14) FAILED") |
| 228 |
} |
| 229 |
else { incr(testok) } |
| 230 |
|
| 231 |
set(str15,strconcat(str14,str14)) |
| 232 |
if (ne(strlen(str15),132)) |
| 233 |
{ |
| 234 |
call reportfail("strlen(str15) FAILED") |
| 235 |
} |
| 236 |
else { incr(testok) } |
| 237 |
|
| 238 |
if (ne(index(str15,"at",10),130)) |
| 239 |
{ |
| 240 |
call reportfail("index(str15,at,10) FAILED") |
| 241 |
} |
| 242 |
else { incr(testok) } |
| 243 |
|
| 244 |
set(str16,strconcat(str15,str15)) |
| 245 |
if (ne(strlen(str16),264)) |
| 246 |
{ |
| 247 |
call reportfail("strlen(str16) FAILED") |
| 248 |
} |
| 249 |
else { incr(testok) } |
| 250 |
|
| 251 |
if (ne(index(str16,"at",20),262)) |
| 252 |
{ |
| 253 |
call reportfail("index(str16,at,20) FAILED") |
| 254 |
} |
| 255 |
else { incr(testok) } |
| 256 |
|
| 257 |
if (ne(substring(str16,260,262)," ba")) |
| 258 |
{ |
| 259 |
call reportfail("substring(str16,260,262) FAILED") |
| 260 |
} |
| 261 |
else { incr(testok) } |
| 262 |
|
| 263 |
call reportSubsection("string tests") |
| 264 |
} |
| 265 |
|