123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- ;;;; srfi-11.test --- exercise SRFI-11 let-values
- ;;;;
- ;;;; Copyright 2004, 2006 Free Software Foundation, Inc.
- ;;;;
- ;;;; This library is free software; you can redistribute it and/or
- ;;;; modify it under the terms of the GNU Lesser General Public
- ;;;; License as published by the Free Software Foundation; either
- ;;;; version 3 of the License, or (at your option) any later version.
- ;;;;
- ;;;; This library is distributed in the hope that it will be useful,
- ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ;;;; Lesser General Public License for more details.
- ;;;;
- ;;;; You should have received a copy of the GNU Lesser General Public
- ;;;; License along with this library; if not, write to the Free Software
- ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- (define-module (test-suite test-srfi-11)
- #:use-module (test-suite lib)
- #:use-module (srfi srfi-11))
- ;;
- ;; let-values
- ;;
- (with-test-prefix "let-values"
- (with-test-prefix "no exprs"
- (pass-if "no values"
- (let-values ()
- #t)))
- (with-test-prefix "one expr"
- (pass-if "no values"
- (let-values ((() (values)))
- #t))
- (pass-if "one value"
- (let-values (((x) (values 1)))
- (equal? x 1)))
- (pass-if "one value as rest"
- (let-values ((x (values 1)))
- (equal? x '(1))))
- (pass-if "two values"
- (let-values (((x y) (values 1 2)))
- (and (equal? x 1)
- (equal? y 2)))))
- (with-test-prefix "two exprs"
- (pass-if "no values each"
- (let-values ((() (values))
- (() (values)))
- #t))
- (pass-if "one value / no values"
- (let-values (((x) (values 1))
- (() (values)))
- (equal? x 1)))
- (pass-if "one value each"
- (let-values (((x) (values 1))
- ((y) (values 2)))
- (and (equal? x 1)
- (equal? y 2))))
- (pass-if-exception "first binding invisible to second expr"
- '(unbound-variable . ".*")
- (let-values (((x) (values 1))
- ((y) (values (1+ x))))
- #f))
- (pass-if "first binding with rest invisible to second expr"
- (let* ((a 1)
- (b (let-values (((a . b) (values 2 3))
- (c (begin (set! a 9) 4)))
- (list a b c))))
- (equal? (cons a b) '(9 2 (3) (4)))))))
- ;;
- ;; let*-values
- ;;
- (with-test-prefix "let*-values"
- (with-test-prefix "no exprs"
- (pass-if "no values"
- (let*-values ()
- #t)))
- (with-test-prefix "one expr"
- (pass-if "no values"
- (let*-values ((() (values)))
- #t))
- (pass-if "one value"
- (let*-values (((x) (values 1)))
- (equal? x 1)))
- (pass-if "one value as rest"
- (let-values ((x (values 1)))
- (equal? x '(1))))
- (pass-if "two values"
- (let*-values (((x y) (values 1 2)))
- (and (equal? x 1)
- (equal? y 2)))))
- (with-test-prefix "two exprs"
- (pass-if "no values each"
- (let*-values ((() (values))
- (() (values)))
- #t))
- (pass-if "one value / no values"
- (let*-values (((x) (values 1))
- (() (values)))
- (equal? x 1)))
- (pass-if "one value each"
- (let*-values (((x) (values 1))
- ((y) (values 2)))
- (and (equal? x 1)
- (equal? y 2))))
- (pass-if "first binding visible to second expr"
- (let*-values (((x) (values 1))
- ((y) (values (1+ x))))
- (and (equal? x 1)
- (equal? y 2))))))
|