|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (test-suite session) |
|
#:use-module (test-suite lib) |
|
#:use-module (ice-9 match) |
|
#:use-module (system base compile) |
|
#:use-module (ice-9 session)) |
|
|
|
(define (find-module mod) |
|
(call/cc (lambda (k) |
|
(apropos-fold-all (lambda (m _) |
|
(and (not (module? m)) (k #f)) |
|
(and (eq? m mod) (k #t))) |
|
#f)))) |
|
(define (find-mod-name mod-name) |
|
(find-module (resolve-module mod-name #f #:ensure #f))) |
|
|
|
|
|
(with-test-prefix "apropos-fold-all" |
|
(pass-if "a root module: ice-9" (find-mod-name '(ice-9))) |
|
(pass-if "a child of test-suite" (find-mod-name '(test-suite lib))) |
|
(pass-if "a non-module" (not (find-mod-name '(ice-999-0)))) |
|
(pass-if "a childish non-module" (not (find-mod-name '(ice-9 ice-999-0)))) |
|
(pass-if "an anonymous module" (find-mod-name (module-name (make-module))))) |
|
|
|
(define (find-interface mod-name) |
|
(let* ((mod (resolve-module mod-name #f #:ensure #f)) |
|
(ifc (and mod (module-public-interface mod)))) |
|
(and ifc |
|
(call/cc (lambda (k) |
|
(apropos-fold-exported (lambda (i _) |
|
(and (eq? i ifc) (k #t))) |
|
#f)))))) |
|
|
|
(with-test-prefix "apropos-fold-exported" |
|
(pass-if "a child of test-suite" (find-interface '(test-suite lib))) |
|
(pass-if "a child of ice-9" (find-interface '(ice-9 session)))) |
|
|
|
(with-test-prefix "procedure-arguments" |
|
|
|
(define-syntax-rule (pass-if-valid-arguments name proc expected) |
|
(pass-if name |
|
(let ((args (procedure-arguments (compile 'proc #:to 'value)))) |
|
(or (equal? args 'expected) |
|
(pk 'invalid-args args #f))))) |
|
|
|
(pass-if-valid-arguments "lambda" |
|
(lambda (a b c) #f) |
|
((required . (a b c)) (optional) (keyword) |
|
(allow-other-keys? . #f) (rest . #f))) |
|
(pass-if-valid-arguments "lambda with rest" |
|
(lambda (a b . r) #f) |
|
((required . (a b)) (optional) (keyword) |
|
(allow-other-keys? . #f) (rest . r))) |
|
(pass-if-valid-arguments "lambda* with optionals" |
|
(lambda* (a b #:optional (p 1) (q 2)) #f) |
|
((required . (a b)) (optional . (p q)) |
|
(keyword) (allow-other-keys? . #f) (rest . #f))) |
|
(pass-if-valid-arguments "lambda* with keywords" |
|
(lambda* (a b #:key (k 42) l) #f) |
|
((required . (a b)) (optional) |
|
(keyword . ((#:k . 3) (#:l . 4))) (allow-other-keys? . #f) |
|
(rest . #f))) |
|
(pass-if-valid-arguments "lambda* with keywords and a-o-k" |
|
(lambda* (a b #:key (k 42) #:allow-other-keys) #f) |
|
((required . (a b)) (optional) |
|
(keyword . ((#:k . 3))) (allow-other-keys? . #t) |
|
(rest . #f))) |
|
(pass-if-valid-arguments "lambda* with optionals, keys, and rest" |
|
(lambda* (a b #:optional o p #:key k l #:rest r) #f) |
|
((required . (a b)) (optional . (o p)) |
|
(keyword . ((#:k . 6) (#:l . 7))) (allow-other-keys? . #f) |
|
(rest . r))) |
|
|
|
(pass-if "aok? is preserved" |
|
|
|
(let* ((proc (compile '(lambda (a b) #f) #:to 'value)) |
|
(args (procedure-arguments proc))) |
|
(set-procedure-property! proc 'arglist (map cdr args)) |
|
(equal? args (procedure-arguments proc)))) |
|
|
|
(pass-if "interpreted procedures (simple)" |
|
(match (procedure-arguments |
|
(eval '(lambda (x y) #f) (current-module))) |
|
(((required _ _) |
|
(optional) |
|
(keyword) |
|
(allow-other-keys? . #f) |
|
(rest . #f)) |
|
#t) |
|
(_ #f))) |
|
|
|
(pass-if "interpreted procedures (complex)" |
|
(match (procedure-arguments |
|
(eval '(lambda* (a b #:optional c #:key d) #f) (current-module))) |
|
(((required _ _) |
|
(optional _) |
|
(keyword (#:d . 3)) |
|
(allow-other-keys? . #f) |
|
(rest . #f)) |
|
#t) |
|
(_ #f)))) |
|
|
|
|
|
|
|
|
|
|