curried-definitions.test 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. (with-test-prefix "define*"
  51. (pass-if "define* works as usual"
  52. (equal? 34
  53. (primitive-eval '(let ()
  54. (define* (foo)
  55. 34)
  56. (foo)))))
  57. (pass-if "define* works as usual (2)"
  58. (equal? 134
  59. (primitive-eval '(let ()
  60. (define* (foo x)
  61. (+ x 34))
  62. (foo 100)))))
  63. (pass-if "currying once"
  64. (equal? 234
  65. (primitive-eval '(let ()
  66. (define* ((foo) x)
  67. (+ x 34))
  68. ((foo) 200)))))
  69. (pass-if "currying twice"
  70. (equal? 334
  71. (primitive-eval '(let ()
  72. (define* (((foo)) x)
  73. (+ x 34))
  74. (((foo)) 300)))))
  75. (pass-if "just a value"
  76. (equal? 444
  77. (primitive-eval '(let ()
  78. (define* foo 444)
  79. foo)))))