srfi-2.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;;; srfi-2.test --- Test suite for Guile's and-let* macro. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2015 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-srfi-2)
  19. #:use-module (test-suite lib)
  20. #:use-module (srfi srfi-2))
  21. (pass-if-equal 1 (and-let* () 1))
  22. (pass-if-equal 2 (and-let* () 1 2))
  23. (pass-if-equal #t (and-let* ()))
  24. (pass-if-equal #f (let ((x #f)) (and-let* (x))))
  25. (pass-if-equal 1 (let ((x 1)) (and-let* (x))))
  26. (pass-if-equal #f (and-let* ((x #f))))
  27. (pass-if-equal 1 (and-let* ((x 1))))
  28. (pass-if-exception "bad clause" '(syntax-error . "Bad clause")
  29. (eval '(and-let* (#f (x 1))) (current-module)))
  30. (pass-if-equal #f (and-let* ((#f) (x 1))))
  31. (pass-if-exception "bad clause" '(syntax-error . "Bad clause")
  32. (eval '(and-let* (2 (x 1))) (current-module)))
  33. (pass-if-equal 1 (and-let* ((2) (x 1))))
  34. (pass-if-equal 2 (and-let* ((x 1) (2))))
  35. (pass-if-equal #f (let ((x #f)) (and-let* (x) x)))
  36. (pass-if-equal "" (let ((x "")) (and-let* (x) x)))
  37. (pass-if-equal "" (let ((x "")) (and-let* (x))))
  38. (pass-if-equal 2 (let ((x 1)) (and-let* (x) (+ x 1))))
  39. (pass-if-equal #f (let ((x #f)) (and-let* (x) (+ x 1))))
  40. (pass-if-equal 2 (let ((x 1)) (and-let* (((positive? x))) (+ x 1))))
  41. (pass-if-equal #t (let ((x 1)) (and-let* (((positive? x))))))
  42. (pass-if-equal #f (let ((x 0)) (and-let* (((positive? x))) (+ x 1))))
  43. (pass-if-equal 3
  44. (let ((x 1)) (and-let* (((positive? x)) (x (+ x 1))) (+ x 1))))
  45. ;; This is marked as must-be-error in the original test suite, but
  46. ;; that's a mistake of the SRFI author who thinks that rebinding
  47. ;; variables in let* is an error; in fact it's allowed in let*
  48. ;; (explicitly since R6RS), so it should be allowed by and-let* too.
  49. (pass-if-equal 4
  50. (let ((x 1))
  51. (and-let* (((positive? x)) (x (+ x 1)) (x (+ x 1))) (+ x 1))))
  52. (pass-if-equal 2
  53. (let ((x 1)) (and-let* (x ((positive? x))) (+ x 1))))
  54. (pass-if-equal 2
  55. (let ((x 1)) (and-let* (((begin x)) ((positive? x))) (+ x 1))))
  56. (pass-if-equal #f
  57. (let ((x 0)) (and-let* (x ((positive? x))) (+ x 1))))
  58. (pass-if-equal #f
  59. (let ((x #f)) (and-let* (x ((positive? x))) (+ x 1))))
  60. (pass-if-equal #f
  61. (let ((x #f)) (and-let* (((begin x)) ((positive? x))) (+ x 1))))
  62. (pass-if-equal #f
  63. (let ((x 1)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  64. (pass-if-equal #f
  65. (let ((x 0)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  66. (pass-if-equal #f
  67. (let ((x #f)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  68. (pass-if-equal 3/2
  69. (let ((x 3)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  70. ;;; srfi-2.test ends here