1 USING: arrays definitions io.streams.string io.streams.duplex
2 kernel math namespaces parser prettyprint prettyprint.config
3 prettyprint.sections sequences tools.test vectors words
4 effects splitting generic.standard prettyprint.private
5 continuations generic compiler.units tools.walker ;
8 [ "4" ] [ 4 unparse ] unit-test
9 [ "1.0" ] [ 1.0 unparse ] unit-test
10 [ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
12 [ "+" ] [ \ + unparse ] unit-test
14 [ "\\ +" ] [ [ \ + ] first unparse ] unit-test
16 [ "{ }" ] [ { } unparse ] unit-test
18 [ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
20 [ "\"hello\\\\backslash\"" ]
21 [ "hello\\backslash" unparse ]
25 ! [ "\u123456" unparse ]
32 [ "f" ] [ f unparse ] unit-test
33 [ "t" ] [ t unparse ] unit-test
35 [ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
37 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
39 [ ] [ \ fixnum see ] unit-test
41 [ ] [ \ integer see ] unit-test
43 [ ] [ \ generic see ] unit-test
45 [ ] [ \ duplex-stream see ] unit-test
47 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
48 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
51 100 \ dup <array> unparse-short
55 : foo ( a -- b ) dup * ; inline
57 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
58 [ [ \ foo see ] with-string-writer ] unit-test
60 : bar ( x -- y ) 2 + ;
62 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
63 [ [ \ bar see ] with-string-writer ] unit-test
88 \ blah f "inferred-effect" set-word-prop
89 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
92 : check-see ( expect name -- )
97 [ parse-fresh drop ] with-compilation-unit
99 "prettyprint.tests" lookup see
100 ] with-string-writer "\n" split but-last
106 "IN: prettyprint.tests"
107 "GENERIC: method-layout"
109 "USING: math prettyprint.tests ;"
110 "M: complex method-layout"
111 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
114 "USING: math prettyprint.tests ;"
115 "M: fixnum method-layout ;"
117 "USING: math prettyprint.tests ;"
118 "M: integer method-layout ;"
120 "USING: kernel prettyprint.tests ;"
121 "M: object method-layout ;"
125 "method-layout" method-test check-see
130 "USING: io kernel sequences words ;"
131 "IN: prettyprint.tests"
132 ": retain-stack-layout ( x -- )"
133 " dup stream-readln stream-readln"
134 " >r [ define ] map r>"
139 "retain-stack-layout" retain-stack-test check-see
144 "USING: kernel math sequences strings ;"
145 "IN: prettyprint.tests"
146 ": soft-break-layout ( x y -- ? )"
148 " over hashcode over hashcode number="
149 " [ sequence= ] [ 2drop f ] if"
150 " ] [ 2drop f ] if ;"
154 "soft-break-layout" soft-break-test check-see
157 : another-retain-layout-test
159 "USING: kernel sequences ;"
160 "IN: prettyprint.tests"
161 ": another-retain-layout ( seq1 seq2 quot -- newseq )"
162 " -rot 2dup dupd min-length [ each drop roll ] map"
163 " >r 3drop r> ; inline"
167 "another-retain-layout" another-retain-layout-test check-see
170 : another-soft-break-test
172 "USING: namespaces parser sequences ;"
173 "IN: prettyprint.tests"
174 ": another-soft-break-layout ( node -- quot )"
176 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
180 "another-soft-break-layout" another-soft-break-test
186 "USING: io kernel parser ;"
187 "IN: prettyprint.tests"
188 ": string-layout-test ( error -- )"
189 " \"Expected \" write dup unexpected-want expected>string write"
190 " \" but got \" write unexpected-got expected>string print ;"
195 "string-layout-test" string-layout check-see
198 ! Define dummy words for the below...
199 : <NSRect> ( a b c d -- e ) ;
200 : <PixelFormat> ( -- fmt ) ;
203 \ send soft "break-after" set-word-prop
205 : final-soft-break-test
207 "USING: kernel sequences ;"
208 "IN: prettyprint.tests"
209 ": final-soft-break-layout ( class dim -- view )"
210 " >r \"alloc\" send 0 0 r>"
212 " <PixelFormat> \"initWithFrame:pixelFormat:\" send"
213 " dup 1 \"setPostsBoundsChangedNotifications:\" send"
214 " dup 1 \"setPostsFrameChangedNotifications:\" send ;"
218 "final-soft-break-layout" final-soft-break-test check-see
223 "USING: arrays combinators continuations kernel sequences ;"
224 "IN: prettyprint.tests"
225 ": narrow-layout ( obj -- )"
227 " { [ dup continuation? ] [ append ] }"
228 " { [ dup not ] [ drop reverse ] }"
229 " { [ dup pair? ] [ delete ] }"
234 "narrow-layout" narrow-test check-see
237 : another-narrow-test
239 "IN: prettyprint.tests"
240 ": another-narrow-layout ( -- obj )"
253 "another-narrow-layout" another-narrow-test check-see
258 "IN: prettyprint.tests"
259 "TUPLE: class-see-layout ;"
261 "IN: prettyprint.tests"
262 "GENERIC: class-see-layout ( x -- y )"
264 "USING: prettyprint.tests ;"
265 "M: class-see-layout class-see-layout ;"
269 "class-see-layout" class-see-test check-see
272 [ ] [ \ effect-in synopsis drop ] unit-test
276 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
278 "generic-decl-test" "prettyprint.tests" lookup
279 [ see ] with-string-writer =
283 [ \ + (step-into-execute) ] (remove-breakpoints)
286 [ [ (step-into-execute) ] ] [
287 [ (step-into-execute) ] (remove-breakpoints)
291 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
295 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
298 [ ] [ 1 \ + curry unparse drop ] unit-test
300 [ ] [ 1 \ + compose unparse drop ] unit-test
302 GENERIC: generic-see-test-with-f ( obj -- obj )
304 M: f generic-see-test-with-f ;
306 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
307 [ { POSTPONE: f generic-see-test-with-f } see ] with-string-writer
310 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
311 [ \ f \ generic-see-test-with-f method see ] with-string-writer
314 PREDICATE: predicate-see-test < integer even? ;
316 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
317 [ \ predicate-see-test see ] with-string-writer
320 INTERSECTION: intersection-see-test sequence number ;
322 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
323 [ \ intersection-see-test see ] with-string-writer
326 [ ] [ \ compose see ] unit-test
327 [ ] [ \ curry see ] unit-test
329 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test