scripts/test.hex
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
#!/usr/bin/env hex
"./lib/utils.hbx" read "utils.hbx" !
; --- Globals
0x0 "TEST-COUNT" :
0x0 "SUCCESSES" :
0x0 "FAILURES" :
() "ERRORS" :
() "FAILS" :
0x0 "RESULT" :
; --- Utilities
(
"_test_current" :
TEST-COUNT 0x1 + "TEST-COUNT" :
(
(_test_current .)
(
"." print
SUCCESSES 0x1 + "SUCCESSES" :
)
(
"x" print
FAILURES 0x1 + "FAILURES" :
FAILS TEST-COUNT dec ' cat "FAILS" :
)
if
)
(
; Store error
ERRORS " - Test #" TEST-COUNT dec cat ": " cat error cat ' cat "ERRORS" :
"x" print
FAILURES 0x1 + "FAILURES" :
FAILS TEST-COUNT dec ' cat "FAILS" :
)
try
"_test_current" #
) "test" ::
; --- Test Definitions
(
(0x1 "a" : a 0x1 ==)
("a" # 0x1)
("aaa" type "string" == 0x1 type "integer" == () type "quotation" == and and)
((0x1 0x2 +) . 0x3 ==)
;4
("0x2 0x2 -" "test.hex" ! 0x0 ==)
(0x4 0x5 + 0x9 ==)
(0x5 0x3 - 0x2 ==)
(0x5 0x2 * 0xa ==)
;8
(0x5 0x2 / 0x2 ==)
(0x4 0x2 % 0x0 ==)
(0x10101 0x01010 & 0x0 ==)
(0x10111 0x01000 | 0x11111 ==)
;12
(0x1 0x1 ^ 0x0 ==)
(0x1 ~ 0xfffffffe ==)
(0x1 0x4 << 0x10 ==)
(0x10 0x4 >> 0x1 ==)
;16
("10" int 0x10 ==)
(0x10 str "10" ==)
(0xa dec "10" ==)
("10" hex 0xa ==)
;20
("aaa" "aaa" ==)
(0x20 0x20 ==)
(0x21 0x22 !=)
("abba" "aaa" !=)
;24
(0x2 0x1 >)
(0x2 0x2 >=)
(0x2 0x3 <)
(0x3 0x3 <=)
;28
(0x2 0x3 and)
(0x1 0x0 or)
(0x1 0x0 xor)
(0x1 0x1 xor not)
;32
((() not) (error) try "[symbol not] Integer required" ==)
((() 0x1 xor) (error) try "[symbol xor] Two integers required" ==)
("aaaaa" len 0x5 ==)
("hello" " world" cat "hello world" ==)
;36
((0x1 "a") ("b") cat (0x1 "a" "b") ==)
((0x1 0x3 puts "aaa") len 0x4 ==)
((0x2 0x3 0x4) 0x2 get 0x4 ==)
("abcde" 0x1 get "b" ==)
;40
("a/b/c" "t-path" : (t-path "/" index 0x0 >=) (t-path "/" "\\" sub "t-path" :) while t-path "a\\b\\c" == "t-path" #)
("assets\"" "\"" "/" sub "assets/" ==)
(("" () cat) (error) try "[symbol cat] Two quotations or two strings required" ==)
((0x4 len) (error) try "[symbol len] Quotation or string required" ==)
;44
("this is a test" "is" index 0x2 ==)
(("a" 0x1 "b") "b" index 0x2 ==)
("abc" "d" index 0xffffffff ==)
(("0" "0" "0" "0") "." join "0.0.0.0"==)
;48
("0.0.0.0" "." split ("0" "0" "0" "0") ==)
("Hello, World!" "Hello" "Goodbye" sub "Goodbye, World!" ==)
("test" "test.txt" write "test.txt" read "test" ==)
("!" "test.txt" append "test.txt" read "test!" ==)
;52
("rm test.txt" exec 0x0 ==)
("rm test.txt" run 0x0 get 0x1 ==)
("ls web/contents" run 0x1 get "\n" split len 0x8 ==)
(args 0x1 get "scripts/test.hbx" ==)
;56
((args len 0x2 ==) ("two") ("no") if "two" ==)
((dup *) "square" :: 0x2 square 0x4 == "square" #)
(0x1 "tmp-a" : (tmp-a 0x3 <) (tmp-a 0x1 + "tmp-a" :) while tmp-a 0x3 ==)
(symbols len 0x65 ==)
;60
((0x2 0x0 /) (error "[symbol /] Division by zero" ==) try)
(error "" ==)
("a" ' ' ' ((("a"))) ==)
((0x1 0x2 0x3) (dup dup * *) map (0x1 0x8 0x1b) ==)
;64
(0x2 dup stack (0x2 0x2) ==)
((dup *) "square" :: 0x3 square 0x9 == "square" #)
(("test" throw) (error "test" ==) try)
(0x1 0x2 swap drop drop drop stack (0x2) == swap drop) ; Also make sure to clear the stack polluted with #65
;68
(("aaa" "puts" :) (error) try "[symbol :] Failed to store symbol 'puts'" ==)
(("puts" #) (error) try "[symbol #] Cannot free native symbol 'puts'" ==)
(("aaa" 0x2 :) (error) try "[symbol :] Symbol name must be a string" ==)
((0x2 #) (error) try "[symbol #] Symbol name must be a string" ==)
;72
(("puts" .) (error) try "[symbol .] Quotation required" ==)
(((puts) "test.hex" !) (error) try "[symbol !] Quotation must contain only integers" ==)
(("3" 0x3 +) (error) try "[symbol +] Two integers required" ==)
(("3" 0x3 -) (error) try "[symbol -] Two integers required" ==)
;76
((0x2 0x3 0x3) (0x2 0x3) > 0x1 ==)
((0x2 0x3) (0x2 0x1) > 0x1 ==)
((test abc) (test cde) < 0x1 ==)
(("test" "abc") ("test" "abc") <= 0x1 ==)
;80
("hello" "" split ("h" "e" "l" "l" "o") ==)
(("3" 0x3 /) (error) try "[symbol /] Two integers required" ==)
((0x4 0x0 %) (error) try "[symbol %] Division by zero" ==)
((() 0x3 %) (error) try "[symbol %] Two integers required" ==)
;84
((() 0x3 &) (error) try "[symbol &] Two integers required" ==)
((0x2 "" |) (error) try "[symbol |] Two integers required" ==)
((() "" ^) (error) try "[symbol ^] Two integers required" ==)
((() 0x1 >>) (error) try "[symbol >>] Two integers required" ==)
;88
((() 0x1 <<) (error) try "[symbol <<] Two integers required" ==)
(("" ~) (error) try "[symbol ~] Integer required" ==)
((0x5 int) (error) try "[symbol int] String representing a hexadecimal integer required" ==)
(((0x3) int) (error) try "[symbol int] String representing a hexadecimal integer required" ==)
;92
(("5" str) (error) try "[symbol str] Integer required" ==)
((("aaa") str) (error) try "[symbol str] Integer required" ==)
(("10" dec) (error) try "[symbol dec] Integer required" ==)
((0x5 hex) (error) try "[symbol hex] String representing a decimal integer required" ==)
;96
("0x2" 0x2 == 0x0 ==)
("0x2" (0x2) !=)
((0x3 "aaa") ("aaa" 0x5) > 0x0 ==)
(("aaa" 0x5) ("aaa" 0x5 0x4) >= 0x0 ==)
;100
((test "aaa") (test "aaa" 0x5) < 0x1 ==)
(("aaa" 0x5) ("" "aaa" 0x5) <= 0x1 ==)
(("a" "b" and) (error) try "[symbol and] Two integers required" ==)
((0x1 "a" or) (error) try "[symbol or] Two integers required" ==)
;104
(("abc" 0x3 get) (error) try "[symbol get] Index out of range" ==)
(((0x2) 0x2 get) (error) try "[symbol get] Index out of range" ==)
((() 0x0 get) (error) try "[symbol get] Index out of range" ==)
((0x4 0x4 get) (error) try "[symbol get] Quotation or string required" ==)
;108
(("abc" "b" get) (error) try "[symbol get] Index must be an integer" ==)
(((0x4 "aa" test) "b" get) (error) try "[symbol get] Index must be an integer" ==)
("a" ord 0x61 ==)
(0x61 chr "a" ==)
;112
("=" ord 0x3d ==)
(0x3d chr "=" ==)
(0xffffffff dec "-1" ==)
(0x80 chr "" ==)
;116
("abc" ord 0xffffffff ==)
((0x56 ord) (error) try "[symbol ord] String required" ==)
(("t" chr) (error) try "[symbol chr] Integer required" ==)
((() chr) (error) try "[symbol chr] Integer required" ==)
;120
(
"test\ntest\\ntest\t\"hello\"!" "_str" :
_str "test1.txt" write
"test1.txt" read _str == "_str" #
"rm test1.txt" exec drop
)
(("a" not) (error) try "[symbol not] Integer required" ==)
((0x1 () xor) (error) try "[symbol xor] Two integers required" ==)
((() "aaa" cat) (error) try "[symbol cat] Two quotations or two strings required" ==)
;124
((0x4 () cat) (error) try "[symbol cat] Two quotations or two strings required" ==)
((0x4 len) (error) try "[symbol len] Quotation or string required" ==)
((0x1 0x4 index) (error) try "[symbol index] Quotation or string required" ==)
((("a" 0x2 "b") "-" join) (error) try "[symbol join] Quotation must contain only strings" ==)
;128
((("a" "b" "c") 0x1 join) (error) try "[symbol join] Quotation and string required" ==)
(("a" 0x1 split) (error) try "[symbol split] Two strings required" ==)
((("aaa") "a" "b" sub) (error) try "[symbol sub] Three strings required" ==)
((0x1 read) (error) try "[symbol read] String required" ==)
;132
(("invalid-file.txt" read) (error) try "[symbol read] Could not open file for reading: invalid-file.txt" ==)
(("test" "invalid-file//" write) (error) try "[symbol write] Could not open file for writing: invalid-file//" ==)
(((0x2 0x4 "a") "test.txt" write) (error) try "[symbol write] Quotation must contain only integers" == "rm test.txt" exec drop)
((0x2 "test.txt" write) (error) try "[symbol write] String or quotation of integers required" ==)
;136
(("a" () write) (error) try "[symbol write] String required" ==)
(("aaa" "invalid-file//" append) (error) try "[symbol append] Could not open file for appending: invalid-file//" ==)
(((0x2 "" 0x5) "test.txt" append) (error) try "[symbol append] Quotation must contain only integers" == "rm test.txt" exec drop)
((0x2 "test.txt" append) (error) try "[symbol append] String or quotation of integers required" ==)
;140
(("a" 0x1 append) (error) try "[symbol append] String required" ==)
(("error" exit) (error) try "[symbol exit] Integer required" ==)
((0x1 exec) (error) try "[symbol exec] String required" ==)
((() run) (error) try "[symbol run] String required" ==)
;144
((() () "" if) (error) try "[symbol if] Three quotations required" ==)
((() "" while) (error) try "[symbol while] Two quotations required" ==)
((() 0x1 try) (error) try "[symbol try] Two quotations required" ==)
((0x1 throw) (error) try "[symbol throw] String required" ==)
;148
((() 0x1 map) (error) try "[symbol map] Two quotations required" ==)
(
(
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
0x1 0x2 "a" () "c" 0xf4 0xffffffff "d" "eeeee" "test \n aaa"
) len "130" hex ==
)
;150
;------------------------------------------------------------------------;
; utils.hex tests ;
;------------------------------------------------------------------------;
(0x2 (0x1) (0x1) when 0x1 == swap drop)
(0x2 (0x0) (0x1) when 0x2 ==)
("ccc" ("aaa") ("bbb") when "ccc" ==)
((0x1) ("yes") ("no") unless "no" == swap drop)
;154
(() 0x1 push (0x1) ==)
((0x1 0x2 0x3) pop (0x1 0x2) ==)
(0x0 (0x1 0x2 0x3) cons (0x0 0x1 0x2 0x3) ==)
((0x1 0x2 0x3) uncons stack (0x1 (0x2 0x3)) == swap drop swap drop)
;158
((0x1 0x2 0x3) 0x0 swons (0x0 0x1 0x2 0x3) ==)
((0x1 0x2 0x3) unswons stack ((0x2 0x3) 0x1) == swap drop swap drop)
("a" "b" over stack "_r" : drop drop drop ("a" "b" "a") _r == "_r" #)
(0x1 (0x2) dip stack "_r" : (0x2 0x1) _r == "_r" # drop drop)
;162
("This is a test" "This" begins)
("This is a test" "this" begins not)
("This is a test" "test" ends)
("This is a test" "Test" ends not)
;166
((0x1 0x2 0x3 0x5 0x6) "a" 0x3 ins (0x1 0x2 0x3 "a" 0x5 0x6) ==)
((0x1 0x2 0x3 0x5 0x6) "a" 0x0 ins ("a" 0x1 0x2 0x3 0x5 0x6) ==)
((0x1 0x2 0x3 0x5 0x6) "a" 0x4 ins (0x1 0x2 0x3 0x5 "a" 0x6) ==)
((0x1 0x2 0x3 0x5 0x6) "a" 0x1 ins (0x1 "a" 0x2 0x3 0x5 0x6) ==)
;170
((0x4 0x3 "c" 0x2 "b" 0x1 "a") reverse ("a" 0x1 "b" 0x2 "c" 0x3 0x4) ==)
((0x1) reverse (0x1) ==)
((0x1 0x2) reverse (0x2 0x1) ==)
(() reverse () ==)
;174
((0x2 0x3 0x4) "a" 0x1 set (0x2 "a" 0x4) ==)
((0x2 0x3 0x4) "a" 0x0 set ("a" 0x3 0x4) ==)
((0x2 0x3 0x4) "a" 0x2 set (0x2 0x3 "a") ==)
((0x2 0x3 0x4 0x5) "a" 0x3 set (0x2 0x3 0x4 "a") ==)
;178
((0x3 0x5 0x2 0x1 0x4) (>) sort (0x1 0x2 0x3 0x4 0x5) ==)
((0x3 0x5 0x2 0x1 0x4) (<) sort (0x5 0x4 0x3 0x2 0x1) ==)
(("a" "c" "b") (>) sort ("a" "b" "c") ==)
(("a" "c" "b") (<) sort ("c" "b" "a") ==)
;182
((0x1 0x2 0x3 0x4) 0x2 rem (0x1 0x2 0x4) ==)
(((0x1 0x2 0x3 0x4) 0x4 rem) (error) try "[symbol rem] Index out of bounds" ==)
((0x1 0x2 0x3 0x4) 0x0 rem (0x2 0x3 0x4) ==)
((0x1 0x2 0x3 0x4) 0x3 rem (0x1 0x2 0x3) ==)
;186
("This is a test! And another test" "test" "sample" gsub "This is a sample! And another sample" ==)
("This is a test! And another test" "sample" "test" gsub "This is a test! And another test" ==)
((0x1 0x4 0x5) min 0x1 ==)
((0x1 0x4 0x5) max 0x5 ==)
;190
("${0}, ${1}!" ("hello" "world") fmt "hello, world!" ==)
(("" ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n") fmt) (error) try "[symbol fmt] Only a maximum of 10 placeholders are supported" ==)
("This is a ${0}, and another ${0}, and yet another ${0}" ("test") fmt "This is a test, and another test, and yet another test" ==)
("${0}, ${2}, ${1}!" ("first" "third") fmt "first, ${2}, third!" ==)
;194
(0x0 "_a" : (0x1 0x2 0x3) (_a + "_a" :) each _a 0x6 == "_a" #)
((0x1 0x2 0x3 0x4) (0x2 % 0x0 ==) filter (0x2 0x4) ==)
("Testing" 0x1 0x3 slice "est" ==)
(("a" 0xffffffff 0x0 slice) (error) try "[symbol slice] Index out of bounds" ==)
;198
(("a" 0x0 0x1 slice) (error) try "[symbol slice] Index out of bounds" ==)
("a" 0x0 0x0 slice "a" ==)
("" ("-" cat) 0x5 times "-----" ==)
;201
; --- Edge cases: empty string operations
("" len 0x0 ==)
("" "" cat "" ==)
;203
; --- Edge cases: negative integer arithmetic
(0xffffffff 0x1 + 0x0 ==)
(0x0 0x1 - 0xffffffff ==)
(0xffffffff dec "-1" ==)
(0x0 0x1 - dec "-1" ==)
;207
; --- Empty quotation operations
(() len 0x0 ==)
(() () cat () ==)
(() () == 0x1 ==)
(() (0x1) == 0x0 ==)
;211
; --- Nested try blocks: inner error caught, outer still works
(
(
("error-inner" throw) (error) try
)
(error)
try
"error-inner" ==
)
; try with no error: body executes, catch block skipped
(
0x0 "try-result" :
(0x1 "try-result" :) () try
try-result 0x1 == "try-result" #
)
;213
; --- Symbol equality: comparing symbols to non-symbol types
(0x1 0x2 == 0x0 ==)
("abc" "abc" == 0x1 ==)
("abc" "xyz" == 0x0 ==)
;216
; --- Large quotation: create and measure
(
(
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa
) len "100" hex ==
)
;217
;------------------------------------------------------------------------;
; Refactoring-safety tests: ownership, stack, error recovery, boundaries ;
;------------------------------------------------------------------------;
; --- Group 1: Quotation ownership & deep-copy correctness
; A: map with quotation-typed results — copies action results into new quotation
((0x1 0x2) (') map ((0x1) (0x2)) ==)
; B: if then-branch — copies string items from thenBlock quotation
(("hello" len 0x3 >) ("yes") ("no") if "yes" ==)
; C: if else-branch — copies string items from elseBlock quotation
(("hi" len 0xa >) ("yes") ("no") if "no" ==)
; D: while building a quotation — copy cycle across iterations
(
() "_wd_q" :
0x0 "_wd_i" :
(_wd_i 0x5 <)
(
_wd_q _wd_i ' cat "_wd_q" :
_wd_i 0x1 + "_wd_i" :
)
while
_wd_q (0x0 0x1 0x2 0x3 0x4) == "_wd_q" # "_wd_i" #
)
;221
; E: nested while loops — copy+free cycle across nested iterations (3x3=9)
(
0x0 "_we_sum" :
0x0 "_we_i" :
(_we_i 0x3 <)
(
0x0 "_we_j" :
(_we_j 0x3 <)
(
_we_sum 0x1 + "_we_sum" :
_we_j 0x1 + "_we_j" :
)
while
"_we_j" #
_we_i 0x1 + "_we_i" :
)
while
_we_sum 0x9 == "_we_sum" # "_we_i" #
)
; F: user-defined operator (::) body — hex_push copies operator body items
(
(' cat) "_wrapcat" ::
(0x1) 0x2 _wrapcat (0x1 0x2) == "_wrapcat" #
)
; G: each on heterogeneous quotation (int + string + nested quotation)
(
0x0 "_eg_count" :
("hello" 0x2a (0x1 0x2)) (drop _eg_count 0x1 + "_eg_count" :) each
_eg_count 0x3 == "_eg_count" #
)
; H: filter retaining quotation-typed elements
((() (0x1) (0x1 0x2)) (len 0x0 >) filter ((0x1) (0x1 0x2)) ==)
;225
; I: get returning a quotation from a nested structure — returned item is owned independently
(((0x1 0x2) (0x3 0x4)) 0x1 get (0x3 0x4) ==)
; J: cat of nested quotations — result owns deep copies of both sources
(((0x1) (0x2)) ((0x3)) cat ((0x1) (0x2) (0x3)) ==)
;227
; --- Group 2: Stack manipulation with complex types
; K: swap two quotations — both independently owned after swap
((0x1 0x2) (0x3 0x4) swap (0x1 0x2) == swap (0x3 0x4) == and)
; L: quote + dup + dequote — dup produces independent deep copy
(0x1 ' dup . swap . and)
; M: 4-level nested quotation dequote chain — recursive hex_copy_item
(((((0x2a)))) . . . . 0x2a ==)
; N: variable re-binding inside loop — : doesn't alias old and new values
(
(0x1) "_vr_v" :
0x0 "_vr_i" :
(_vr_i 0x3 <)
(
_vr_v _vr_i ' cat "_vr_v" :
_vr_i 0x1 + "_vr_i" :
)
while
_vr_v (0x1 0x0 0x1 0x2) == "_vr_v" # "_vr_i" #
)
;231
; --- Group 3: Error recovery paths
; O: try inside while, error thrown mid-loop, loop resumes after catch
(
0x0 "_to_i" :
(_to_i 0x3 <)
(
((_to_i 0x2 ==) ("found-2" throw) when)
(error drop)
try
_to_i 0x1 + "_to_i" :
)
while
_to_i 0x3 == "_to_i" #
)
; P: throw with dynamically-built error message — string ownership through throw/error
(("error-" "42" cat throw) (error) try "error-42" ==)
; Q: sequential try blocks have independent error state
(
("first" throw) (error) try "first" ==
("second" throw) (error) try "second" ==
and
)
;234
; --- Group 4: Boundary conditions and untested symbols
; R: timestamp returns a 2-element quotation of integers (seconds + microseconds)
(timestamp type "quotation" ==)
; S: timestamp seconds element is non-negative
(timestamp 0x0 get 0x0 >=)
; T: 256-element quotation at HEX_STACK_SIZE boundary
(
() "_bq_q" :
0x0 "_bq_i" :
(_bq_i 0x100 <)
(
_bq_q _bq_i ' cat "_bq_q" :
_bq_i 0x1 + "_bq_i" :
)
while
_bq_q len 0x100 == "_bq_q" # "_bq_i" #
)
; U: split where delimiter not found — returns single-element quotation
("abc" "x" split ("abc") ==)
;238
) "TESTS" :
; --- Run Tests
0x0 "_c" :
(_c TESTS len <)
(
TESTS _c get
test
_c 0x1 + "_c" :
)
while
"_c" #
; --- Report
"\nSuccessful Tests: " print SUCCESSES dec print "/" print SUCCESSES FAILURES + dec puts
(ERRORS len 0x0 >)
(
"Errors:" warn
0x0 "_c" :
(_c ERRORS len <)
(
ERRORS _c get
warn
_c 0x1 + "_c" :
)
while
"_c" #
0x1 "RESULT" :
)
when
(FAILS len 0x0 >)
(
"Failed Tests: " FAILS ", " join cat warn
0x1 "RESULT" :
)
when
RESULT exit
|