poe.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ;;;; poe.test --- exercise ice-9/poe.scm -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2003, 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-ice-9-poe)
  19. #:use-module (test-suite lib)
  20. #:use-module (ice-9 poe))
  21. ;;
  22. ;; pure-funcq
  23. ;;
  24. (with-test-prefix "pure-funcq"
  25. (with-test-prefix "no args"
  26. (define obj (vector 123)) ;; not gc'ed
  27. (define called #f)
  28. (define (foo)
  29. (set! called #t)
  30. obj)
  31. (let ((func (pure-funcq foo)))
  32. (pass-if "called first"
  33. (set! called #f)
  34. (and (eq? obj (func))
  35. called))
  36. (pass-if "not called second"
  37. (set! called #f)
  38. (and (eq? obj (func))
  39. (not called)))))
  40. (with-test-prefix "1 arg"
  41. (define obj1 (vector 123)) ;; not gc'ed
  42. (define obj2 (vector 456)) ;; not gc'ed
  43. (define called #f)
  44. (define (foo sym)
  45. (set! called #t)
  46. (case sym
  47. ((x) obj1)
  48. ((y) obj2)
  49. (else (error "oops"))))
  50. (let ((func (pure-funcq foo)))
  51. (pass-if "called first x"
  52. (set! called #f)
  53. (and (eq? obj1 (func 'x))
  54. called))
  55. (pass-if "not called second x"
  56. (set! called #f)
  57. (and (eq? obj1 (func 'x))
  58. (not called)))
  59. (pass-if "called first y"
  60. (set! called #f)
  61. (and (eq? obj2 (func 'y))
  62. called))
  63. (pass-if "not called second y"
  64. (set! called #f)
  65. (and (eq? obj2 (func 'y))
  66. (not called)))
  67. (pass-if "not called third x"
  68. (set! called #f)
  69. (and (eq? obj1 (func 'x))
  70. (not called))))))
  71. ;;
  72. ;; perfect-funcq
  73. ;;
  74. (with-test-prefix "perfect-funcq"
  75. (with-test-prefix "no args"
  76. (define called #f)
  77. (define (foo)
  78. (set! called #t)
  79. 'foo)
  80. (let ((func (perfect-funcq 31 foo)))
  81. (pass-if "called first"
  82. (set! called #f)
  83. (and (eq? 'foo (func))
  84. called))
  85. (pass-if "not called second"
  86. (set! called #f)
  87. (and (eq? 'foo (func))
  88. (not called)))))
  89. (with-test-prefix "1 arg"
  90. (define called #f)
  91. (define (foo str)
  92. (set! called #t)
  93. (string->number str))
  94. (let ((func (perfect-funcq 31 foo)))
  95. (define s1 "123")
  96. (define s2 "123")
  97. (pass-if "called first s1"
  98. (set! called #f)
  99. (and (= 123 (func s1))
  100. called))
  101. (pass-if "not called second s1"
  102. (set! called #f)
  103. (and (= 123 (func s1))
  104. (not called)))
  105. (pass-if "called first s2"
  106. (set! called #f)
  107. (and (= 123 (func s2))
  108. called))
  109. (pass-if "not called second s2"
  110. (set! called #f)
  111. (and (= 123 (func s2))
  112. (not called))))))