Debian Codegraph @

test/include/srfi-197-test.scm

raw
1 ;;from reference implementation
2 ;; https://github.com/scheme-requests-for-implementation/srfi-197/blob/master/test.scm
3 ;;(include "./srfi-64-minimal.scm")
4
5 (define (exclamation x) (string-append x "!"))
6
7 (define (foo+bar x) (values (string-append x "foo") (string-append x "bar")))
8
9 (test-begin "Pipeline Operators")
10
11 (test-equal "chain" "bazbarfoo!"
12 (chain ""
13 (string-append "foo" _)
14 (string-append "bar" _)
15 (string-append "baz" _)
16 (exclamation _)))
17
18 (test-equal "chain with mixed _ position" "barfoobaz"
19 (chain ""
20 (string-append _ "foo")
21 (string-append "bar" _)
22 (string-append _ "baz")))
23
24 (test-equal "chain with _ in operator position" 3
25 (chain +
26 (_ 1 2)))
27
28 (test-equal "chain without _" "barbazqux"
29 (chain ""
30 (string-append _ "foo")
31 (string-append "bar" "baz")
32 (string-append _ "qux")))
33
34 (test-equal "chain multiple _" "quxfoo/quxbar"
35 (chain "qux"
36 (foo+bar _)
37 (string-append _ "/" _)))
38
39 (test-equal "chain _ ..." "bazquxfooquxbar"
40 (chain "qux"
41 (foo+bar _)
42 (string-append "baz" _ ...)))
43
44 (test-equal "chain _ _ ..." "quxfoobazquxbar"
45 (chain "qux"
46 (foo+bar _)
47 (string-append _ "baz" _ ...)))
48
49 (test-equal "chain with custom _" "bazbarfoo!"
50 (chain "" <>
51 (string-append "foo" <>)
52 (string-append "bar" <>)
53 (string-append "baz" <>)
54 (exclamation <>)))
55
56 (test-equal "chain with custom ..." "bazquxfooquxbar"
57 (chain "qux" - ---
58 (foo+bar -)
59 (string-append "baz" - ---)))
60
61 (test-equal "chain-and" "bazbarfoo!"
62 (chain-and ""
63 (string-append "foo" _)
64 (string-append "bar" _)
65 (string-append "baz" _)
66 (exclamation _)))
67
68 (test-equal "chain-and with mixed _ position" "barfoobaz"
69 (chain-and ""
70 (string-append _ "foo")
71 (string-append "bar" _)
72 (string-append _ "baz")))
73
74 (test-equal "chain-and without _" "barbazqux"
75 (chain-and ""
76 (string-append "foo" _)
77 (string-append "bar" "baz")
78 (string-append _ "qux")))
79
80 (test-equal "chain-and short-circuit" #f
81 (chain-and ""
82 (string-append "foo" _)
83 (equal? _ "bar")
84 (string-append "baz" _)
85 (exclamation _)))
86
87 (test-equal "chain-and short-circuit first" #f
88 (chain-and #f
89 (not _)))
90
91 (test-equal "chain-and with custom _" "bazbarfoo!"
92 (chain-and "" <>
93 (string-append "foo" <>)
94 (string-append "bar" <>)
95 (string-append "baz" <>)
96 (exclamation <>)))
97
98 (test-equal "chain-when" "bazfoo"
99 (chain-when ""
100 ((= (+ 2 2) 4) (string-append "foo" _))
101 ((= (+ 2 2) 5) (string-append "bar" _))
102 (#t (string-append "baz" _))))
103
104 (test-equal "chain-when with mixed _ position" "barfooqux"
105 (chain-when ""
106 (#t (string-append _ "foo"))
107 (#t (string-append "bar" _))
108 (#f (string-append _ "baz"))
109 (#t (string-append _ "qux"))))
110
111 (test-equal "chain-when without _" "barqux"
112 (chain-when ""
113 (#t (string-append _ "foo"))
114 (#t (string-append "bar"))
115 (#f (string-append _ "baz"))
116 (#t (string-append _ "qux"))))
117
118 (test-equal "chain-when with custom _" "bazfoo"
119 (chain-when "" <>
120 ((= (+ 2 2) 4) (string-append "foo" <>))
121 ((= (+ 2 2) 5) (string-append "bar" <>))
122 (#t (string-append "baz" <>))))
123
124 (test-equal "chain-lambda" "bazbarfoo!"
125 ((chain-lambda (string-append "foo" _)
126 (string-append "bar" _)
127 (string-append "baz" _)
128 (exclamation _))
129 ""))
130
131 (test-equal "chain-lambda one step" "foobar"
132 ((chain-lambda (string-append "foo" _)) "bar"))
133
134 (test-equal "chain-lambda with mixed _ position" "barfoobaz"
135 ((chain-lambda (string-append _ "foo")
136 (string-append "bar" _)
137 (string-append _ "baz"))
138 ""))
139
140 (test-equal "chain-lambda multiple _" "foobarbazqux"
141 ((chain-lambda (string-append _ "bar" _)
142 (string-append _ "qux"))
143 "foo"
144 "baz"))
145
146 (test-equal "chain-lambda without _" "barqux"
147 ((chain-lambda (string-append "bar")
148 (string-append _ "qux"))))
149
150 (test-equal "chain-lambda _ ..." "foobarbazqux"
151 ((chain-lambda (string-append "foo" _ ...)
152 (string-append _ "qux"))
153 "bar"
154 "baz"))
155
156 (test-equal "chain-lambda _ _ ..." "foobarbazquxquux"
157 ((chain-lambda (string-append _ "bar" _ ...)
158 (string-append _ "quux"))
159 "foo"
160 "baz"
161 "qux"))
162
163 (test-equal "chain-lambda with custom _" "bazbarfoo!"
164 ((chain-lambda <>
165 (string-append "foo" <>)
166 (string-append "bar" <>)
167 (string-append "baz" <>)
168 (exclamation <>))
169 ""))
170
171 (test-equal "chain-lambda with custom ..." "foobarbazqux"
172 ((chain-lambda - ---
173 (string-append "foo" - ---)
174 (string-append - "qux"))
175 "bar"
176 "baz"))
177
178 (test-equal "nest" '(1 2 (3 (4) 5))
179 (nest (quote _)
180 (1 2 _)
181 (3 _ 5)
182 (_)
183 4))
184
185 (test-equal "nest with custom _" '(1 2 (3 (4) 5))
186 (nest <>
187 (quote <>)
188 (1 2 <>)
189 (3 <> 5)
190 (<>)
191 4))
192
193 (test-equal "nested nest" '(1 2 3 (4 5 6))
194 (nest (nest _2 (quote _2) (1 2 3 _2) _ 6)
195 (_ 5 _2)
196 4))
197
198 (test-equal "nest-reverse" '(1 2 (3 (4) 5))
199 (nest-reverse 4
200 (_)
201 (3 _ 5)
202 (1 2 _)
203 (quote _)))
204
205 (test-equal "nest-reverse with custom _" '(1 2 (3 (4) 5))
206 (nest-reverse 4 <>
207 (<>)
208 (3 <> 5)
209 (1 2 <>)
210 (quote <>)))
211
212 (test-end "Pipeline Operators")