mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
The current implementation of srfi-11s let-values allows later clauses to access and modify variables bound in earlier clauses when the clause is not a proper list. * module/srfi/srfi-11.scm (let-values): Fix switched variable names. * test-suite/tests/srfi-11.test (let-values): Add test checking that the variable cannot be changed in later clauses.
139 lines
3.3 KiB
Text
139 lines
3.3 KiB
Text
;;;; 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))))))
|