srfi-26.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ; CONFIDENCE TEST FOR IMPLEMENTATION OF SRFI-26
  2. ; =============================================
  3. ;
  4. ; Sebastian.Egner@philips.com, 3-Jun-2002.
  5. ;
  6. ; This file checks a few assertions about the implementation.
  7. ; If you run it and no error message is issued, the implementation
  8. ; is correct on the cases that have been tested.
  9. ;
  10. ; compliance:
  11. ; Scheme R5RS with
  12. ; SRFI-23: error
  13. ;
  14. ; loading this file into Scheme 48 0.57 after 'cut.scm' has been loaded:
  15. ; ,open srfi-23
  16. ; ,load check.scm
  17. ; (check expr)
  18. ; evals expr and issues an error if it is not #t.
  19. (define-module (test-srfi-26)
  20. #:use-module (test-suite lib)
  21. #:use-module (srfi srfi-26))
  22. (define (check expr)
  23. (pass-if "cut/cute" (eval expr (interaction-environment))))
  24. ; (check-all)
  25. ; runs several tests on cut and reports.
  26. (define (check-all)
  27. (for-each
  28. check
  29. '( ; cuts
  30. (equal? ((cut list)) '())
  31. (equal? ((cut list <...>)) '())
  32. (equal? ((cut list 1)) '(1))
  33. (equal? ((cut list <>) 1) '(1))
  34. (equal? ((cut list <...>) 1) '(1))
  35. (equal? ((cut list 1 2)) '(1 2))
  36. (equal? ((cut list 1 <>) 2) '(1 2))
  37. (equal? ((cut list 1 <...>) 2) '(1 2))
  38. (equal? ((cut list 1 <...>) 2 3 4) '(1 2 3 4))
  39. (equal? ((cut list 1 <> 3 <>) 2 4) '(1 2 3 4))
  40. (equal? ((cut list 1 <> 3 <...>) 2 4 5 6) '(1 2 3 4 5 6))
  41. (equal? (let* ((x 'wrong) (y (cut list x))) (set! x 'ok) (y)) '(ok))
  42. (equal?
  43. (let ((a 0))
  44. (map (cut + (begin (set! a (+ a 1)) a) <>)
  45. '(1 2))
  46. a)
  47. 2)
  48. ; cutes
  49. (equal? ((cute list)) '())
  50. (equal? ((cute list <...>)) '())
  51. (equal? ((cute list 1)) '(1))
  52. (equal? ((cute list <>) 1) '(1))
  53. (equal? ((cute list <...>) 1) '(1))
  54. (equal? ((cute list 1 2)) '(1 2))
  55. (equal? ((cute list 1 <>) 2) '(1 2))
  56. (equal? ((cute list 1 <...>) 2) '(1 2))
  57. (equal? ((cute list 1 <...>) 2 3 4) '(1 2 3 4))
  58. (equal? ((cute list 1 <> 3 <>) 2 4) '(1 2 3 4))
  59. (equal? ((cute list 1 <> 3 <...>) 2 4 5 6) '(1 2 3 4 5 6))
  60. (equal?
  61. (let ((a 0))
  62. (map (cute + (begin (set! a (+ a 1)) a) <>)
  63. '(1 2))
  64. a)
  65. 1))))
  66. ; run the checks when loading
  67. (with-test-prefix "SRFI-26"
  68. (check-all))