Abdullah Alamoudi | 121e1d9 | 2016-03-26 23:02:39 +0300 | [diff] [blame] | 1 | echo Testing select on lists... |
| 2 | eval x = { |
| 3 | [a = 3; b = "I see London"], |
| 4 | [a = 2; b = "I see France"], |
| 5 | [a = 1; b = "I see Alain's funky pants"] |
| 6 | } |
| 7 | same $x.a, {3, 2, 1} |
| 8 | same $x.b, {"I see London", "I see France", "I see Alain's funky pants"} |
| 9 | same $x.c, {undefined, undefined, undefined} |
| 10 | same {}.a, {} |
| 11 | |
Abdullah Alamoudi | ac683db | 2016-02-23 00:59:31 +0300 | [diff] [blame] | 12 | ///////////////////////////////// |
| 13 | echo Testing basic math... |
| 14 | eval x = (1 + 2) |
| 15 | same $x, 3 |
| 16 | eval x = (3 - 1) |
| 17 | same $x, 2 |
| 18 | eval x = (2 * 3) |
| 19 | same $x, 6 |
| 20 | eval x = (8 / 2) |
| 21 | same $x, 4 |
| 22 | |
| 23 | echo Testing extreme numbers... |
| 24 | same string(real("INF")), "real(\"INF\")" |
| 25 | same string(real("-INF")), "real(\"-INF\")" |
| 26 | same string(real("NaN")), "real(\"NaN\")" |
| 27 | diff real("NaN"), real("NaN") |
| 28 | same real("INF"), real("INF") |
| 29 | same real("-INF"), real("-INF") |
| 30 | diff real("INF"), real("-INF") |
| 31 | same 0.0, -(0.0) |
| 32 | same 0.0, real("-0.0") |
| 33 | same string(0.0), "0.0" |
| 34 | same string(-0.0), "-0.0" |
| 35 | |
| 36 | ///////////////////////////////// |
| 37 | echo Testing basic attributes in a ClassAd... |
| 38 | eval x = [ |
| 39 | a = 1; |
| 40 | b = 2.0; |
| 41 | c = "alain"; |
| 42 | d = true; |
| 43 | atime = absTime("2004-01-01"); |
| 44 | rtime = relTime("2+25:14:16.123"); |
| 45 | l = {1, 1, 2, 3, 5}; |
| 46 | e = error; |
| 47 | u = undefined; |
| 48 | ] |
| 49 | same $x.a, 1 |
| 50 | same $x.b, 2.0 |
| 51 | same $x.c, "alain" |
| 52 | same $x.d, true |
| 53 | same $x.atime, absTime("2004-01-01"); |
| 54 | same $x.rtime, relTime("2+25:14:16.123"); |
| 55 | same $x.l, {1, 1, 2, 3, 5} |
| 56 | same $x.l[4], 5 |
| 57 | same $x.e, error |
| 58 | same $x.u, undefined |
| 59 | same isinteger($x.a), true |
| 60 | same isinteger($x.b), false |
| 61 | same isreal($x.b), true |
| 62 | same isreal($x.c), false |
| 63 | same isstring($x.c), true |
| 64 | same isstring($x.d), false |
| 65 | same isboolean($x.d), true |
| 66 | same isboolean($x.c), false |
| 67 | same isabstime($x.atime), true |
| 68 | same isabstime($x.rtime), false |
| 69 | same isreltime($x.rtime), true |
| 70 | same isreltime($x.atime), false |
| 71 | same islist($x.l), true |
| 72 | same islist($x.a), false |
| 73 | same iserror($x.e), true |
| 74 | same iserror($x.u), false |
| 75 | same isundefined($x.u), true |
| 76 | same isundefined($x.e), false |
| 77 | |
| 78 | // Note that testing XML relies on the ClassAd from |
| 79 | // the above testing. |
| 80 | // echo Testing XML... |
| 81 | // eval y = [ a = 2; b = "Lisp rocks"; ] |
| 82 | // writexml tmp.xml {$x, $y} |
| 83 | // readxml z tmp.xml |
| 84 | // same $x, $z[0] |
| 85 | // same $y, $z[1] |
| 86 | |
| 87 | ///////////////////////////////// |
Abdullah Alamoudi | 121e1d9 | 2016-03-26 23:02:39 +0300 | [diff] [blame] | 88 | |
Abdullah Alamoudi | ac683db | 2016-02-23 00:59:31 +0300 | [diff] [blame] | 89 | |
| 90 | ///////////////////////////////// |
| 91 | echo Testing subscripts |
| 92 | eval x = [ |
| 93 | a = 3; |
| 94 | b = "alain"; |
| 95 | ab = 4; |
| 96 | ] |
| 97 | same $x["a"], 3 |
| 98 | same $x["b"], "alain" |
| 99 | same $x["c"], error |
| 100 | eval d = $x["c"] |
| 101 | same $x[strcat("a", "b")], 4 |
| 102 | eval x = {"a", "b", "c"} |
| 103 | same $x[0], "a" |
| 104 | same $x[1], "b" |
| 105 | same $x[2], "c" |
| 106 | same $x[3], error |
| 107 | |
| 108 | ///////////////////////////////// |
| 109 | echo Testing multiple semicolons... |
| 110 | eval x = [ |
| 111 | ;; |
| 112 | a = 3;; |
| 113 | b = 4;; |
| 114 | ] |
| 115 | |
| 116 | ///////////////////////////////// |
| 117 | echo Testing functions... |
| 118 | same int(3), 3 |
| 119 | same int(3.9), 3 |
| 120 | same int("3.9"), 3 |
| 121 | same int(absTime("1970-01-01T:00:00:01Z")), 1 |
| 122 | same int(reltime("01:00:01")), 3601 |
| 123 | eval y = int(absTime("1970-01-01T:00:00:01Z")) |
| 124 | same $y, 1 |
| 125 | |
| 126 | same real(3), 3.0 |
| 127 | same real(3.9), 3.9 |
| 128 | same real("3.9"), 3.9 |
| 129 | same real(absTime("1970-01-01T:00:00:01Z")), 1.0 |
| 130 | same real(reltime("01:00:01")), 3601.0 |
| 131 | |
| 132 | same string("alain"), "alain" |
| 133 | same string(1), "1" |
| 134 | |
| 135 | same floor(3.9), 3 |
| 136 | same floor("3.9"), 3 |
| 137 | |
| 138 | same ceiling(3.9), 4 |
| 139 | same ceiling("3.9"), 4 |
| 140 | |
| 141 | same round(3.1), 3 |
| 142 | same round(3.9), 4 |
| 143 | |
| 144 | same strcat("", "roy"), "roy" |
| 145 | same strcat("alain", ""), "alain" |
| 146 | same strcat("alain", "roy"), "alainroy" |
| 147 | same strcat(14, " bottles of root beer"), "14 bottles of root beer" |
| 148 | |
| 149 | same substr("abcde", 1), "bcde" |
| 150 | same substr("abcde", 4), "e" |
| 151 | same substr("abcde", 5), "" |
| 152 | same substr("abcde", 1, 2), "bc" |
| 153 | same substr("abcde", 4, 2), "e" |
| 154 | |
| 155 | same strcmp("alain", "roy") < 0, true |
| 156 | same strcmp("roy", "alain") > 0, true |
| 157 | same strcmp("alain", "alain"), 0 |
| 158 | |
| 159 | same stricmp("alain", "ALAIN"), 0 |
| 160 | same stricmp("alain", "roy") < 0, true |
| 161 | |
| 162 | same tolower("ALAIN"), "alain") |
| 163 | same toupper("alain"), "ALAIN") |
| 164 | same tolower(true), "true") |
| 165 | same toupper(true), "TRUE") |
| 166 | |
| 167 | same member(1, {1, 2, 3}), true |
| 168 | same member(4, {1, 2, 3}), false |
| 169 | |
| 170 | same regexp("Alain.*Roy", "Alain Aslag Roy"), true |
| 171 | same regexp("alain.*roy", "Alain Aslag Roy"), false |
| 172 | same regexp("alain.*roy", "Alain Aslag Roy", "i"), true |
| 173 | |
| 174 | //same regexpMember("b.*", {}), false |
| 175 | //same regexpMember("b.*", {"aa"}), false |
| 176 | //same regexpMember("b.*", {"aa", "bb"}), true |
| 177 | //same regexpMember("b.*", {"bb", "aa"}), true |
| 178 | //same regexpMember("b.*", {1, "bb"} ), error |
| 179 | |
| 180 | |
| 181 | eval t = absTime("1970-01-02T:03:04:05Z") |
| 182 | same splitTime($t).year, 1970 |
| 183 | same splitTime($t).month, 1 |
| 184 | same splitTime($t).day, 2 |
| 185 | same splitTime($t).hours, 3 |
| 186 | same splitTime($t).minutes, 4 |
| 187 | same splitTime($t).seconds, 5 |
| 188 | same splitTime($t).offset, 0 |
| 189 | |
| 190 | |
| 191 | |
| 192 | eval t = absTime("1970-01-02T:03:04:05-06:00") |
| 193 | eval tt = splitTime($t) |
| 194 | same splitTime($t).year, 1970 |
| 195 | same splitTime($t).month, 1 |
| 196 | same splitTime($t).day, 2 |
| 197 | same splitTime($t).hours, 3 |
| 198 | same splitTime($t).minutes, 4 |
| 199 | same splitTime($t).seconds, 5 |
| 200 | same splitTime($t).offset, -21600 |
| 201 | |
| 202 | |
| 203 | |
| 204 | eval t = relTime("1d2h3m4.5s") |
| 205 | eval tt = splitTime($t) |
| 206 | same splitTime($t).days, 1 |
| 207 | same splitTime($t).hours, 2 |
| 208 | same splitTime($t).minutes, 3 |
| 209 | same splittime($t).seconds, 4.5 |
| 210 | eval tt = splitTime($t) |
| 211 | |
| 212 | |
| 213 | eval t = absTime("1997-08-30T16:04:05-0500") |
| 214 | eval f = formatTime($t, "%m %d %Y") |
| 215 | same $f, "08 30 1997" |
| 216 | eval f = formatTime($t, "%H %M %S") |
| 217 | same $f, "16 04 05" |
| 218 | eval f = formatTime($t, "%A %a") |
| 219 | same $f, "Saturday Sat" |
| 220 | eval f = formatTime($t, "%B %b") |
| 221 | same $f, "August Aug" |
| 222 | eval f = formatTime(splitTime($t), "%H:%M:%S") |
| 223 | same $f, "16:04:05" |
| 224 | eval f = formatTime($t) |
| 225 | same $f, "Sat Aug 30 16:04:05 1997" |
| 226 | |
| 227 | same size({}), 0 |
| 228 | same size({1}), 1 |
| 229 | same size({1, 2, 3, 4, 5}), 5 |
| 230 | same size([]), 0 |
| 231 | same size([a = 1;]), 1 |
| 232 | same size([a = 1; b = 2;]), 2 |
| 233 | same size(""), 0 |
| 234 | same size("a"), 1 |
| 235 | same size("ab"), 2 |
| 236 | same size(3), error |
| 237 | same size(3.4), error |
| 238 | |
| 239 | eval list0 = {} |
| 240 | eval list1 = {1} |
| 241 | eval list5 = {1, 2, 3, 4, 5} |
| 242 | |
| 243 | same sum($list0), undefined |
| 244 | same avg($list0), undefined |
| 245 | same min($list0), undefined |
| 246 | same max($list0), undefined |
| 247 | // #### Do we really want these to be false and true? |
| 248 | same anycompare("<", $list0, 3), false |
| 249 | same allcompare("<", $list0, 3), true |
| 250 | |
| 251 | same sum($list1), 1 |
| 252 | same avg($list1), 1.0 |
| 253 | same min($list1), 1 |
| 254 | same max($list1), 1 |
| 255 | same anycompare("<", $list1, 3), true |
| 256 | same allcompare("<", $list1, 3), true |
| 257 | |
| 258 | same sum($list5), 15 |
| 259 | same avg($list5), 3.0 |
| 260 | same min($list5), 1 |
| 261 | same max($list5), 5 |
| 262 | same anycompare("<", $list5, 3), true |
| 263 | same allcompare("<", $list5, 3), false |
| 264 | |
| 265 | same ifThenElse(1+1==2, 3, 4), 3 |
| 266 | same ifThenElse(1+1==3,3,4), 4 |
| 267 | same ifThenElse(ERROR,3,4), ERROR |
| 268 | same ifThenElse(UNDEFINED,3,4), UNDEFINED |
| 269 | |
| 270 | same interval(1), "1" |
| 271 | same interval(60*2 + 1), "2:01" |
| 272 | same interval(3600*3 + 60*2 + 1), "3:02:01" |
| 273 | same interval(3600*24*4 + 3600*3 + 60*2 + 1), "4+03:02:01" |
| 274 | |
| 275 | //same regexps("[abc]*([def]*)[ghi]*","aaaabbbbcccccdddeeefffggghhhiii","\\1"), "dddeeefff" |
| 276 | //same regexps("[abc]*([def]*)[ghi]*","abcdefghi","\\0"), "abcdefghi" |
| 277 | //same regexps("[abc]*([def]*)[ghi]*","abcdefghi","\\2"), error |
| 278 | //same regexps("[abc]*([def]*)[ghi]*","NO","\\0"), "" |
| 279 | |
| 280 | |
| 281 | echo Testing eval |
| 282 | same eval("1+1"), 2 |
| 283 | same eval(1+1), 2 |
| 284 | same eval("1+"), ERROR |
| 285 | eval x = [ A = 1; B = 2; C = eval("A+B"); ] |
| 286 | same $x.C, 3 |
| 287 | |
| 288 | echo Testing boolean expressions |
| 289 | echo Testing && operator |
| 290 | same false, false && false |
| 291 | same false, false && undefined |
| 292 | same false, false && true |
| 293 | same false, false && error |
| 294 | |
| 295 | same false, undefined && false |
| 296 | same undefined, undefined && undefined |
| 297 | same undefined, undefined && true |
| 298 | same error, undefined && error |
| 299 | |
| 300 | same false, true && false |
| 301 | same undefined, true && undefined |
| 302 | same true, true && true |
| 303 | same error, true && error |
| 304 | |
| 305 | same error, error && false |
| 306 | same error, error && undefined |
| 307 | same error, error && true |
| 308 | same error, error && error |
| 309 | |
| 310 | |
| 311 | echo Testing || operator |
| 312 | same false, false || false |
| 313 | same undefined, false || undefined |
| 314 | same true, false || true |
| 315 | same error, false || error |
| 316 | |
| 317 | same undefined, undefined || false |
| 318 | same undefined, undefined || undefined |
| 319 | same true, undefined || true |
| 320 | same error, undefined || error |
| 321 | |
| 322 | same true, true || false |
| 323 | same true, true || undefined |
| 324 | same true, true || true |
| 325 | same true, true || error |
| 326 | |
| 327 | same error, error || false |
| 328 | same error, error || undefined |
| 329 | same error, error || true |
| 330 | same error, error || error |
| 331 | |
| 332 | |
| 333 | echo Testing ! operator |
| 334 | same true, !false |
| 335 | same undefined, !undefined |
| 336 | same false, !true |
| 337 | same error, !error |
| 338 | |
| 339 | |
| 340 | echo Testing ? operator |
| 341 | same false, false ? true : false |
| 342 | same true, false ? false : true |
| 343 | same undefined, false ? true : undefined |
| 344 | same true, false ? undefined : true |
| 345 | |
| 346 | same true, true ? true : false |
| 347 | same false, true ? false : true |
| 348 | same true, true ? true : undefined |
| 349 | same undefined, true ? undefined : true |
| 350 | |
| 351 | echo Testing characters with negative ascii values |
| 352 | // # the following used to not even parse on some systems |
| 353 | same "–", "–" |
| 354 | |
| 355 | echo Testing stringListsIntersect() |
| 356 | same true, stringListsIntersect("one,two","two,three") |
| 357 | same false, stringListsIntersect("one,two","three,four") |
| 358 | same false, stringListsIntersect("one,two","three,four",";") |
| 359 | same true, stringListsIntersect("one,two","one") |
| 360 | same true, stringListsIntersect("one, two","two, three") |
| 361 | same true, stringListsIntersect("one,two","two,three",",") |
| 362 | same true, stringListsIntersect("one;two","two;three",";") |
| 363 | same undefined, stringListsIntersect("one,two",undefined) |
| 364 | same undefined, stringListsIntersect(undefined,"one,two" ) |