| 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 |
|
| 18 |
(define-module (test-suite test-curried-definitions) |
| 19 |
#:use-module (test-suite lib) |
| 20 |
#:use-module (ice-9 curried-definitions)) |
| 21 |
|
| 22 |
(with-test-prefix "define" |
| 23 |
(pass-if "define works as usual" |
| 24 |
(equal? 34 |
| 25 |
(primitive-eval '(let () |
| 26 |
(define (foo) |
| 27 |
34) |
| 28 |
(foo))))) |
| 29 |
(pass-if "define works as usual (2)" |
| 30 |
(equal? 134 |
| 31 |
(primitive-eval '(let () |
| 32 |
(define (foo x) |
| 33 |
(+ x 34)) |
| 34 |
(foo 100))))) |
| 35 |
(pass-if "currying once" |
| 36 |
(equal? 234 |
| 37 |
(primitive-eval '(let () |
| 38 |
(define ((foo) x) |
| 39 |
(+ x 34)) |
| 40 |
((foo) 200))))) |
| 41 |
(pass-if "currying twice" |
| 42 |
(equal? 334 |
| 43 |
(primitive-eval '(let () |
| 44 |
(define (((foo)) x) |
| 45 |
(+ x 34)) |
| 46 |
(((foo)) 300))))) |
| 47 |
|
| 48 |
(pass-if "just a value" |
| 49 |
(equal? 444 |
| 50 |
(primitive-eval '(let () |
| 51 |
(define foo 444) |
| 52 |
foo)))) |
| 53 |
|
| 54 |
(pass-if "docstring" |
| 55 |
(equal? "Doc" |
| 56 |
(primitive-eval '(let () |
| 57 |
(define (((foo a) b c) d) |
| 58 |
"Doc" |
| 59 |
42) |
| 60 |
(procedure-documentation foo))))) |
| 61 |
|
| 62 |
(pass-if "define-public" |
| 63 |
(eqv? 6 |
| 64 |
(primitive-eval '(let () |
| 65 |
(define-public (((f a) b) c) |
| 66 |
(+ a b c)) |
| 67 |
(((f 1) 2) 3))))) |
| 68 |
|
| 69 |
;; FIXME: how to test for define-public actually making |
| 70 |
;; a public binding? |
| 71 |
|
| 72 |
(pass-if "define-public and docstring" |
| 73 |
(equal? "Addition curried." |
| 74 |
(primitive-eval '(let () |
| 75 |
(define-public (((f a) b) c) |
| 76 |
"Addition curried." |
| 77 |
(+ a b c)) |
| 78 |
(procedure-documentation f)))))) |
| 79 |
|
| 80 |
(with-test-prefix "define*" |
| 81 |
(pass-if "define* works as usual" |
| 82 |
(equal? 34 |
| 83 |
(primitive-eval '(let () |
| 84 |
(define* (foo) |
| 85 |
34) |
| 86 |
(foo))))) |
| 87 |
(pass-if "define* works as usual (2)" |
| 88 |
(equal? 134 |
| 89 |
(primitive-eval '(let () |
| 90 |
(define* (foo x) |
| 91 |
(+ x 34)) |
| 92 |
(foo 100))))) |
| 93 |
(pass-if "currying once" |
| 94 |
(equal? 234 |
| 95 |
(primitive-eval '(let () |
| 96 |
(define* ((foo) x) |
| 97 |
(+ x 34)) |
| 98 |
((foo) 200))))) |
| 99 |
(pass-if "currying twice" |
| 100 |
(equal? 334 |
| 101 |
(primitive-eval '(let () |
| 102 |
(define* (((foo)) x) |
| 103 |
(+ x 34)) |
| 104 |
(((foo)) 300))))) |
| 105 |
|
| 106 |
(pass-if "just a value" |
| 107 |
(equal? 444 |
| 108 |
(primitive-eval '(let () |
| 109 |
(define* foo 444) |
| 110 |
foo)))) |
| 111 |
(pass-if "docstring" |
| 112 |
(equal? "Doc" |
| 113 |
(primitive-eval '(let () |
| 114 |
(define* (((f a) b c) #:optional d) |
| 115 |
"Doc" |
| 116 |
42) |
| 117 |
(procedure-documentation f))))) |
| 118 |
|
| 119 |
(pass-if "define*-public" |
| 120 |
(eqv? 6 |
| 121 |
(primitive-eval '(let () |
| 122 |
(define*-public (((f a) b) #:optional c) |
| 123 |
(+ a b c)) |
| 124 |
(((f 1) 2) 3))))) |
| 125 |
|
| 126 |
(pass-if "define*-public and docstring" |
| 127 |
(equal? "Addition curried." |
| 128 |
(primitive-eval '(let () |
| 129 |
(define*-public (((f a) b) #:key (c 3)) |
| 130 |
"Addition curried." |
| 131 |
(+ a b c)) |
| 132 |
(procedure-documentation f)))))) |