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
38 [ "( a b -- c d )" ] [
39 { "a" "b" } { "c" "d" } <effect> effect>string
43 { } { "c" "d" } <effect> effect>string
47 { "a" "b" } { } <effect> effect>string
51 { } { } <effect> effect>string
54 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
56 [ ] [ \ fixnum see ] unit-test
58 [ ] [ \ integer see ] unit-test
60 [ ] [ \ generic see ] unit-test
62 [ ] [ \ duplex-stream see ] unit-test
64 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
65 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
68 100 \ dup <array> unparse-short
72 : foo ( a -- b ) dup * ; inline
74 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
75 [ [ \ foo see ] with-string-writer ] unit-test
77 : bar ( x -- y ) 2 + ;
79 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
80 [ [ \ bar see ] with-string-writer ] unit-test
105 \ blah f "inferred-effect" set-word-prop
106 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
109 : check-see ( expect name -- )
114 [ parse-fresh drop ] with-compilation-unit
116 "prettyprint.tests" lookup see
117 ] with-string-writer "\n" split but-last
123 "IN: prettyprint.tests"
124 "GENERIC: method-layout"
126 "USING: math prettyprint.tests ;"
127 "M: complex method-layout"
128 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
131 "USING: math prettyprint.tests ;"
132 "M: fixnum method-layout ;"
134 "USING: math prettyprint.tests ;"
135 "M: integer method-layout ;"
137 "USING: kernel prettyprint.tests ;"
138 "M: object method-layout ;"
142 "method-layout" method-test check-see
147 "USING: io kernel sequences words ;"
148 "IN: prettyprint.tests"
149 ": retain-stack-layout ( x -- )"
150 " dup stream-readln stream-readln"
151 " >r [ define ] map r>"
156 "retain-stack-layout" retain-stack-test check-see
161 "USING: kernel math sequences strings ;"
162 "IN: prettyprint.tests"
163 ": soft-break-layout ( x y -- ? )"
165 " over hashcode over hashcode number="
166 " [ sequence= ] [ 2drop f ] if"
167 " ] [ 2drop f ] if ;"
171 "soft-break-layout" soft-break-test check-see
174 : another-retain-layout-test
176 "USING: kernel sequences ;"
177 "IN: prettyprint.tests"
178 ": another-retain-layout ( seq1 seq2 quot -- newseq )"
179 " -rot 2dup dupd min-length [ each drop roll ] map"
180 " >r 3drop r> ; inline"
184 "another-retain-layout" another-retain-layout-test check-see
187 : another-soft-break-test
189 "USING: namespaces parser sequences ;"
190 "IN: prettyprint.tests"
191 ": another-soft-break-layout ( node -- quot )"
193 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
197 "another-soft-break-layout" another-soft-break-test
203 "USING: io kernel parser ;"
204 "IN: prettyprint.tests"
205 ": string-layout-test ( error -- )"
206 " \"Expected \" write dup unexpected-want expected>string write"
207 " \" but got \" write unexpected-got expected>string print ;"
212 "string-layout-test" string-layout check-see
215 ! Define dummy words for the below...
216 : <NSRect> ( a b c d -- e ) ;
217 : <PixelFormat> ( -- fmt ) ;
220 \ send soft "break-after" set-word-prop
222 : final-soft-break-test
224 "USING: kernel sequences ;"
225 "IN: prettyprint.tests"
226 ": final-soft-break-layout ( class dim -- view )"
227 " >r \"alloc\" send 0 0 r>"
229 " <PixelFormat> \"initWithFrame:pixelFormat:\" send"
230 " dup 1 \"setPostsBoundsChangedNotifications:\" send"
231 " dup 1 \"setPostsFrameChangedNotifications:\" send ;"
235 "final-soft-break-layout" final-soft-break-test check-see
240 "USING: arrays combinators continuations kernel sequences ;"
241 "IN: prettyprint.tests"
242 ": narrow-layout ( obj -- )"
244 " { [ dup continuation? ] [ append ] }"
245 " { [ dup not ] [ drop reverse ] }"
246 " { [ dup pair? ] [ delete ] }"
251 "narrow-layout" narrow-test check-see
254 : another-narrow-test
256 "IN: prettyprint.tests"
257 ": another-narrow-layout ( -- obj )"
270 "another-narrow-layout" another-narrow-test check-see
275 "IN: prettyprint.tests"
276 "TUPLE: class-see-layout ;"
278 "IN: prettyprint.tests"
279 "GENERIC: class-see-layout ( x -- y )"
281 "USING: prettyprint.tests ;"
282 "M: class-see-layout class-see-layout ;"
286 "class-see-layout" class-see-test check-see
289 [ ] [ \ effect-in synopsis drop ] unit-test
293 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
295 "generic-decl-test" "prettyprint.tests" lookup
296 [ see ] with-string-writer =
300 [ \ + (step-into-execute) ] (remove-breakpoints)
303 [ [ (step-into-execute) ] ] [
304 [ (step-into-execute) ] (remove-breakpoints)
308 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
312 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
315 [ ] [ 1 \ + curry unparse drop ] unit-test
317 [ ] [ 1 \ + compose unparse drop ] unit-test
319 GENERIC: generic-see-test-with-f ( obj -- obj )
321 M: f generic-see-test-with-f ;
323 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
324 [ { POSTPONE: f generic-see-test-with-f } see ] with-string-writer
327 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
328 [ \ f \ generic-see-test-with-f method see ] with-string-writer
331 PREDICATE: predicate-see-test < integer even? ;
333 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
334 [ \ predicate-see-test see ] with-string-writer
337 INTERSECTION: intersection-see-test sequence number ;
339 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
340 [ \ intersection-see-test see ] with-string-writer
343 [ ] [ \ compose see ] unit-test
344 [ ] [ \ curry see ] unit-test
346 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test