~ chicken-core (chicken-5) /tests/test-optional.scm
Trap1;;;; test-optional.scm - by Alan Post234(define (test baseline result)5 (assert (equal? baseline result)))67;;8;; basic optional arguments with default value.9;;1011(define (foo0 #!optional a0 a1 a2 a3)12 (list a0 a1 a2 a3))1314(define (foo1 a0 #!optional a1 a2 a3)15 (list a0 a1 a2 a3))1617(define (foo2 a0 a1 #!optional a2 a3)18 (list a0 a1 a2 a3))1920(define (foo3 a0 a1 a2 #!optional a3)21 (list a0 a1 a2 a3))2223(test '(#f #f #f #f) (foo0))24(test '(1 #f #f #f) (foo0 1))25(test '(1 2 #f #f) (foo0 1 2))26(test '(1 2 3 #f) (foo0 1 2 3))27(test '(1 2 3 4) (foo0 1 2 3 4))2829;(test '(#f #f #f #f) (foo1)) ; invalid, too few arguments.30(test '(1 #f #f #f) (foo1 1))31(test '(1 2 #f #f) (foo1 1 2))32(test '(1 2 3 #f) (foo1 1 2 3))33(test '(1 2 3 4) (foo1 1 2 3 4))3435;(test '(#f #f #f #f) (foo2)) ; invalid, too few arguments.36;(test '(1 #f #f #f) (foo2 0)) ; invalid, too few arguments.37(test '(1 2 #f #f) (foo2 1 2))38(test '(1 2 #f #f) (foo2 1 2))39(test '(1 2 3 #f) (foo2 1 2 3))40(test '(1 2 3 4) (foo2 1 2 3 4))4142;(test '(#f #f #f #f) (foo3)) ; invalid, too few arguments.43;(test '(1 #f #f #f) (foo3 1)) ; invalid, too few arguments.44;(test '(1 2 #f #f) (foo3 1 2)) ; invalid, too few arguments.45(test '(1 2 3 #f) (foo3 1 2 3))46(test '(1 2 3 4) (foo3 1 2 3 4))4748;;49;; basic optional arguments with manual default value.50;;5152(define (foo0 #!optional (a0 -1) (a1 -2) (a2 -3) (a3 -4))53 (list a0 a1 a2 a3))5455(define (foo1 a0 #!optional (a1 -2) (a2 -3) (a3 -4))56 (list a0 a1 a2 a3))5758(define (foo2 a0 a1 #!optional (a2 -3) (a3 -4))59 (list a0 a1 a2 a3))6061(define (foo3 a0 a1 a2 #!optional (a3 -4))62 (list a0 a1 a2 a3))636465(test '(-1 -2 -3 -4) (foo0))66(test '(1 -2 -3 -4) (foo0 1))67(test '(1 2 -3 -4) (foo0 1 2))68(test '(1 2 3 -4) (foo0 1 2 3))69(test '(1 2 3 4) (foo0 1 2 3 4))7071;(test '(-1 -2 -3 -4) (foo1)) ; invalid, too few arguments.72(test '(1 -2 -3 -4) (foo1 1))73(test '(1 2 -3 -4) (foo1 1 2))74(test '(1 2 3 -4) (foo1 1 2 3))75(test '(1 2 3 4) (foo1 1 2 3 4))7677;(test '(-1 -2 -3 -4) (foo2)) ; invalid, too few arguments.78;(test '(1 -2 -3 -4) (foo2 0)) ; invalid, too few arguments.79(test '(1 2 -3 -4) (foo2 1 2))80(test '(1 2 -3 -4) (foo2 1 2))81(test '(1 2 3 -4) (foo2 1 2 3))82(test '(1 2 3 4) (foo2 1 2 3 4))8384;(test '(-1 -2 -3 -4) (foo3)) ; invalid, too few arguments.85;(test '(1 -2 -3 -4) (foo3 1)) ; invalid, too few arguments.86;(test '(1 2 -3 -4) (foo3 1 2)) ; invalid, too few arguments.87(test '(1 2 3 -4) (foo3 1 2 3))88(test '(1 2 3 4) (foo3 1 2 3 4))8990;;91;; optional arguments with default value set from previous default.92;;93;; NOTE: these currently fail.9495(define (foo0 #!optional (a0 -1) (a1 (- a0 1)) (a2 (- a1 1)) (a3 (- a2 1)))96 (list a0 a1 a2 a3))9798(define (foo1 a0 #!optional (a1 -2) (a2 (- a1 1)) (a3 (- a2 1)))99 (list a0 a1 a2 a3))100101(define (foo2 a0 a1 #!optional (a2 -3) (a3 (- a2 1)))102 (list a0 a1 a2 a3))103104(define (foo3 a0 a1 a2 #!optional (a3 -4))105 (list a0 a1 a2 a3))106107108(test '(-1 -2 -3 -4) (foo0))109(test '(1 0 -1 -2) (foo0 1))110(test '(1 2 1 0) (foo0 1 2))111(test '(1 2 3 2) (foo0 1 2 3))112(test '(1 2 3 4) (foo0 1 2 3 4))113114;(test '(-1 -2 -3 -4) (foo1)) ; invalid, too few arguments.115(test '(1 -2 -3 -4) (foo1 1))116(test '(1 2 1 0) (foo1 1 2))117(test '(1 2 3 2) (foo1 1 2 3))118(test '(1 2 3 4) (foo1 1 2 3 4))119120;(test '(-1 -2 -3 -4) (foo2)) ; invalid, too few arguments.121;(test '(1 -2 -3 -4) (foo2 0)) ; invalid, too few arguments.122(test '(1 2 -3 -4) (foo2 1 2))123(test '(1 2 3 2) (foo2 1 2 3))124(test '(1 2 3 4) (foo2 1 2 3 4))125126;(test '(-1 -2 -3 -4) (foo3)) ; invalid, too few arguments.127;(test '(1 -2 -3 -4) (foo3 1)) ; invalid, too few arguments.128;(test '(1 2 -3 -4) (foo3 1 2)) ; invalid, too few arguments.129(test '(1 2 3 -4) (foo3 1 2 3))130(test '(1 2 3 4) (foo3 1 2 3 4))