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
104 GENERIC: method-layout
106 M: complex method-layout
107 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
110 M: fixnum method-layout ;
112 M: integer method-layout ;
114 M: object method-layout ;
118 "USING: math prettyprint.tests ;"
119 "M: complex method-layout"
120 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
123 "USING: math prettyprint.tests ;"
124 "M: fixnum method-layout ;"
126 "USING: math prettyprint.tests ;"
127 "M: integer method-layout ;"
129 "USING: kernel prettyprint.tests ;"
130 "M: object method-layout ;"
134 [ \ method-layout see-methods ] with-string-writer "\n" split
139 "USING: io kernel sequences words ;"
140 "IN: prettyprint.tests"
141 ": retain-stack-layout ( x -- )"
142 " dup stream-readln stream-readln"
143 " >r [ define ] map r>"
148 "retain-stack-layout" retain-stack-test check-see
153 "USING: kernel math sequences strings ;"
154 "IN: prettyprint.tests"
155 ": soft-break-layout ( x y -- ? )"
157 " over hashcode over hashcode number="
158 " [ sequence= ] [ 2drop f ] if"
159 " ] [ 2drop f ] if ;"
163 "soft-break-layout" soft-break-test check-see
166 : another-retain-layout-test
168 "USING: kernel sequences ;"
169 "IN: prettyprint.tests"
170 ": another-retain-layout ( seq1 seq2 quot -- newseq )"
171 " -rot 2dup dupd min-length [ each drop roll ] map"
172 " >r 3drop r> ; inline"
176 "another-retain-layout" another-retain-layout-test check-see
179 DEFER: parse-error-file
181 : another-soft-break-test
183 "USING: namespaces sequences ;"
184 "IN: prettyprint.tests"
185 ": another-soft-break-layout ( node -- quot )"
187 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
191 "another-soft-break-layout" another-soft-break-test
197 "USING: io kernel lexer ;"
198 "IN: prettyprint.tests"
199 ": string-layout-test ( error -- )"
200 " \"Expected \" write dup unexpected-want expected>string write"
201 " \" but got \" write unexpected-got expected>string print ;"
206 "string-layout-test" string-layout check-see
209 ! Define dummy words for the below...
210 : <NSRect> ( a b c d -- e ) ;
211 : <PixelFormat> ( -- fmt ) ;
214 \ send soft "break-after" set-word-prop
216 : final-soft-break-test
218 "USING: kernel sequences ;"
219 "IN: prettyprint.tests"
220 ": final-soft-break-layout ( class dim -- view )"
221 " >r \"alloc\" send 0 0 r>"
223 " <PixelFormat> \"initWithFrame:pixelFormat:\" send"
224 " dup 1 \"setPostsBoundsChangedNotifications:\" send"
225 " dup 1 \"setPostsFrameChangedNotifications:\" send ;"
229 "final-soft-break-layout" final-soft-break-test check-see
234 "USING: arrays combinators continuations kernel sequences ;"
235 "IN: prettyprint.tests"
236 ": narrow-layout ( obj -- )"
238 " { [ dup continuation? ] [ append ] }"
239 " { [ dup not ] [ drop reverse ] }"
240 " { [ dup pair? ] [ delete ] }"
245 "narrow-layout" narrow-test check-see
248 : another-narrow-test
250 "IN: prettyprint.tests"
251 ": another-narrow-layout ( -- obj )"
264 "another-narrow-layout" another-narrow-test check-see
267 IN: prettyprint.tests
268 TUPLE: class-see-layout ;
270 IN: prettyprint.tests
271 GENERIC: class-see-layout ( x -- y )
273 USING: prettyprint.tests ;
274 M: class-see-layout class-see-layout ;
278 "IN: prettyprint.tests"
279 "TUPLE: class-see-layout ;"
281 "IN: prettyprint.tests"
282 "GENERIC: class-see-layout ( x -- y )"
286 [ \ class-see-layout see ] with-string-writer "\n" split
291 "USING: prettyprint.tests ;"
292 "M: class-see-layout class-see-layout ;"
296 [ \ class-see-layout see-methods ] with-string-writer "\n" split
299 [ ] [ \ effect-in synopsis drop ] unit-test
303 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
305 "generic-decl-test" "prettyprint.tests" lookup
306 [ see ] with-string-writer =
310 [ \ + (step-into-execute) ] (remove-breakpoints)
313 [ [ (step-into-execute) ] ] [
314 [ (step-into-execute) ] (remove-breakpoints)
318 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
322 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
325 [ ] [ 1 \ + curry unparse drop ] unit-test
327 [ ] [ 1 \ + compose unparse drop ] unit-test
329 GENERIC: generic-see-test-with-f ( obj -- obj )
331 M: f generic-see-test-with-f ;
333 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
334 [ { POSTPONE: f generic-see-test-with-f } see ] with-string-writer
337 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
338 [ \ f \ generic-see-test-with-f method see ] with-string-writer
341 PREDICATE: predicate-see-test < integer even? ;
343 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
344 [ \ predicate-see-test see ] with-string-writer
347 INTERSECTION: intersection-see-test sequence number ;
349 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
350 [ \ intersection-see-test see ] with-string-writer
353 [ ] [ \ compose see ] unit-test
354 [ ] [ \ curry see ] unit-test
356 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test