curried-definitions.test 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ;;;; curried-definitions.test -*- scheme -*-
  2. ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This library is free software; you can redistribute it and/or
  5. ;;;; modify it under the terms of the GNU Lesser General Public
  6. ;;;; License as published by the Free Software Foundation; either
  7. ;;;; version 3 of the License, or (at your option) any later version.
  8. ;;;;
  9. ;;;; This library is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;;; Lesser General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU Lesser General Public
  15. ;;;; License along with this library; if not, write to the Free Software
  16. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (test-suite test-curried-definitions)
  18. #:use-module (test-suite lib)
  19. #:use-module (ice-9 curried-definitions))
  20. (with-test-prefix "define"
  21. (pass-if "define works as usual"
  22. (equal? 34
  23. (primitive-eval '(let ()
  24. (define (foo)
  25. 34)
  26. (foo)))))
  27. (pass-if "define works as usual (2)"
  28. (equal? 134
  29. (primitive-eval '(let ()
  30. (define (foo x)
  31. (+ x 34))
  32. (foo 100)))))
  33. (pass-if "currying once"
  34. (equal? 234
  35. (primitive-eval '(let ()
  36. (define ((foo) x)
  37. (+ x 34))
  38. ((foo) 200)))))
  39. (pass-if "currying twice"
  40. (equal? 334
  41. (primitive-eval '(let ()
  42. (define (((foo)) x)
  43. (+ x 34))
  44. (((foo)) 300)))))
  45. (pass-if "just a value"
  46. (equal? 444
  47. (primitive-eval '(let ()
  48. (define foo 444)
  49. foo))))
  50. (pass-if "docstring"
  51. (equal? "Doc"
  52. (primitive-eval '(let ()
  53. (define (((foo a) b c) d)
  54. "Doc"
  55. 42)
  56. (procedure-documentation foo)))))
  57. (pass-if "define-public"
  58. (eqv? 6
  59. (primitive-eval '(let ()
  60. (define-public (((f a) b) c)
  61. (+ a b c))
  62. (((f 1) 2) 3)))))
  63. ;; FIXME: how to test for define-public actually making
  64. ;; a public binding?
  65. (pass-if "define-public and docstring"
  66. (equal? "Addition curried."
  67. (primitive-eval '(let ()
  68. (define-public (((f a) b) c)
  69. "Addition curried."
  70. (+ a b c))
  71. (procedure-documentation f))))))
  72. (with-test-prefix "define*"
  73. (pass-if "define* works as usual"
  74. (equal? 34
  75. (primitive-eval '(let ()
  76. (define* (foo)
  77. 34)
  78. (foo)))))
  79. (pass-if "define* works as usual (2)"
  80. (equal? 134
  81. (primitive-eval '(let ()
  82. (define* (foo x)
  83. (+ x 34))
  84. (foo 100)))))
  85. (pass-if "currying once"
  86. (equal? 234
  87. (primitive-eval '(let ()
  88. (define* ((foo) x)
  89. (+ x 34))
  90. ((foo) 200)))))
  91. (pass-if "currying twice"
  92. (equal? 334
  93. (primitive-eval '(let ()
  94. (define* (((foo)) x)
  95. (+ x 34))
  96. (((foo)) 300)))))
  97. (pass-if "just a value"
  98. (equal? 444
  99. (primitive-eval '(let ()
  100. (define* foo 444)
  101. foo))))
  102. (pass-if "docstring"
  103. (equal? "Doc"
  104. (primitive-eval '(let ()
  105. (define* (((f a) b c) #:optional d)
  106. "Doc"
  107. 42)
  108. (procedure-documentation f)))))
  109. (pass-if "define*-public"
  110. (eqv? 6
  111. (primitive-eval '(let ()
  112. (define*-public (((f a) b) #:optional c)
  113. (+ a b c))
  114. (((f 1) 2) 3)))))
  115. (pass-if "define*-public and docstring"
  116. (equal? "Addition curried."
  117. (primitive-eval '(let ()
  118. (define*-public (((f a) b) #:key (c 3))
  119. "Addition curried."
  120. (+ a b c))
  121. (procedure-documentation f))))))