srfi-11.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ;;;; srfi-11.test --- exercise SRFI-11 let-values
  2. ;;;;
  3. ;;;; Copyright 2004, 2006 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-suite test-srfi-11)
  19. #:use-module (test-suite lib)
  20. #:use-module (srfi srfi-11))
  21. ;;
  22. ;; let-values
  23. ;;
  24. (with-test-prefix "let-values"
  25. (with-test-prefix "no exprs"
  26. (pass-if "no values"
  27. (let-values ()
  28. #t)))
  29. (with-test-prefix "one expr"
  30. (pass-if "no values"
  31. (let-values ((() (values)))
  32. #t))
  33. (pass-if "one value"
  34. (let-values (((x) (values 1)))
  35. (equal? x 1)))
  36. (pass-if "one value as rest"
  37. (let-values ((x (values 1)))
  38. (equal? x '(1))))
  39. (pass-if "two values"
  40. (let-values (((x y) (values 1 2)))
  41. (and (equal? x 1)
  42. (equal? y 2)))))
  43. (with-test-prefix "two exprs"
  44. (pass-if "no values each"
  45. (let-values ((() (values))
  46. (() (values)))
  47. #t))
  48. (pass-if "one value / no values"
  49. (let-values (((x) (values 1))
  50. (() (values)))
  51. (equal? x 1)))
  52. (pass-if "one value each"
  53. (let-values (((x) (values 1))
  54. ((y) (values 2)))
  55. (and (equal? x 1)
  56. (equal? y 2))))
  57. (pass-if-exception "first binding invisible to second expr"
  58. '(unbound-variable . ".*")
  59. (let-values (((x) (values 1))
  60. ((y) (values (1+ x))))
  61. #f))
  62. (pass-if "first binding with rest invisible to second expr"
  63. (let* ((a 1)
  64. (b (let-values (((a . b) (values 2 3))
  65. (c (begin (set! a 9) 4)))
  66. (list a b c))))
  67. (equal? (cons a b) '(9 2 (3) (4)))))))
  68. ;;
  69. ;; let*-values
  70. ;;
  71. (with-test-prefix "let*-values"
  72. (with-test-prefix "no exprs"
  73. (pass-if "no values"
  74. (let*-values ()
  75. #t)))
  76. (with-test-prefix "one expr"
  77. (pass-if "no values"
  78. (let*-values ((() (values)))
  79. #t))
  80. (pass-if "one value"
  81. (let*-values (((x) (values 1)))
  82. (equal? x 1)))
  83. (pass-if "one value as rest"
  84. (let-values ((x (values 1)))
  85. (equal? x '(1))))
  86. (pass-if "two values"
  87. (let*-values (((x y) (values 1 2)))
  88. (and (equal? x 1)
  89. (equal? y 2)))))
  90. (with-test-prefix "two exprs"
  91. (pass-if "no values each"
  92. (let*-values ((() (values))
  93. (() (values)))
  94. #t))
  95. (pass-if "one value / no values"
  96. (let*-values (((x) (values 1))
  97. (() (values)))
  98. (equal? x 1)))
  99. (pass-if "one value each"
  100. (let*-values (((x) (values 1))
  101. ((y) (values 2)))
  102. (and (equal? x 1)
  103. (equal? y 2))))
  104. (pass-if "first binding visible to second expr"
  105. (let*-values (((x) (values 1))
  106. ((y) (values (1+ x))))
  107. (and (equal? x 1)
  108. (equal? y 2))))))