2.sld 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;; Copyright (C) Oleg Kiselyov (1998). All Rights Reserved.
  2. ;; Made an R7RS library by Taylan Ulrich Bayırlı/Kammer, Copyright (C) 2014.
  3. ;; Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ;; of this software and associated documentation files (the "Software"), to deal
  5. ;; in the Software without restriction, including without limitation the rights
  6. ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ;; copies of the Software, and to permit persons to whom the Software is
  8. ;; furnished to do so, subject to the following conditions:
  9. ;; The above copyright notice and this permission notice shall be included in
  10. ;; all copies or substantial portions of the Software.
  11. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. ;; SOFTWARE.
  18. (define-library (srfi-tests 2)
  19. (export run-tests)
  20. (import
  21. (scheme base)
  22. (scheme eval)
  23. (srfi 2)
  24. (srfi 64)
  25. (srfi-tests aux))
  26. (begin
  27. (define (test-eval form)
  28. (eval form (environment '(scheme base) '(srfi 2))))
  29. ;; We want to check whether 'form' has indeed wrong syntax. We eval it and
  30. ;; check for any exception, which is our best approximation.
  31. (define-syntax test-syntax-error
  32. (syntax-rules ()
  33. ((_ form)
  34. (test-error (test-eval 'form)))))
  35. (define-tests run-tests "SRFI-2"
  36. (test-equal 1 (and-let* () 1))
  37. (test-equal 2 (and-let* () 1 2))
  38. (test-equal #t (and-let* ()))
  39. (test-equal #f (let ((x #f)) (and-let* (x))))
  40. (test-equal 1 (let ((x 1)) (and-let* (x))))
  41. (test-equal #f (and-let* ((x #f))))
  42. (test-equal 1 (and-let* ((x 1))))
  43. (test-syntax-error (and-let* (#f (x 1))))
  44. (test-equal #f (and-let* ((#f) (x 1))))
  45. (test-syntax-error (and-let* (2 (x 1))))
  46. (test-equal 1 (and-let* ((2) (x 1))))
  47. (test-equal 2 (and-let* ((x 1) (2))))
  48. (test-equal #f (let ((x #f)) (and-let* (x) x)))
  49. (test-equal "" (let ((x "")) (and-let* (x) x)))
  50. (test-equal "" (let ((x "")) (and-let* (x))))
  51. (test-equal 2 (let ((x 1)) (and-let* (x) (+ x 1))))
  52. (test-equal #f (let ((x #f)) (and-let* (x) (+ x 1))))
  53. (test-equal 2 (let ((x 1)) (and-let* (((positive? x))) (+ x 1))))
  54. (test-equal #t (let ((x 1)) (and-let* (((positive? x))))))
  55. (test-equal #f (let ((x 0)) (and-let* (((positive? x))) (+ x 1))))
  56. (test-equal 3
  57. (let ((x 1)) (and-let* (((positive? x)) (x (+ x 1))) (+ x 1))))
  58. ;; This is marked as must-be-error in the original test suite; see
  59. ;; comments in the implementation for our rationale for intentionally
  60. ;; breaking off from the specification.
  61. (test-equal 4
  62. (let ((x 1))
  63. (and-let* (((positive? x)) (x (+ x 1)) (x (+ x 1))) (+ x 1))))
  64. (test-equal 2
  65. (let ((x 1)) (and-let* (x ((positive? x))) (+ x 1))))
  66. (test-equal 2
  67. (let ((x 1)) (and-let* (((begin x)) ((positive? x))) (+ x 1))))
  68. (test-equal #f
  69. (let ((x 0)) (and-let* (x ((positive? x))) (+ x 1))))
  70. (test-equal #f
  71. (let ((x #f)) (and-let* (x ((positive? x))) (+ x 1))))
  72. (test-equal #f
  73. (let ((x #f)) (and-let* (((begin x)) ((positive? x))) (+ x 1))))
  74. (test-equal #f
  75. (let ((x 1)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  76. (test-equal #f
  77. (let ((x 0)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  78. (test-equal #f
  79. (let ((x #f)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))))
  80. (test-equal 3/2
  81. (let ((x 3)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y)))))
  82. ))