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 eval
6 accessors make vocabs.parser ;
9 [ "4" ] [ 4 unparse ] unit-test
10 [ "1.0" ] [ 1.0 unparse ] unit-test
11 [ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
13 [ "+" ] [ \ + unparse ] unit-test
15 [ "\\ +" ] [ [ \ + ] first unparse ] unit-test
17 [ "{ }" ] [ { } unparse ] unit-test
19 [ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
21 [ "\"hello\\\\backslash\"" ]
22 [ "hello\\backslash" unparse ]
26 ! [ "\u123456" unparse ]
33 [ "f" ] [ f unparse ] unit-test
34 [ "t" ] [ t unparse ] unit-test
36 [ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
38 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
40 [ ] [ \ fixnum see ] unit-test
42 [ ] [ \ integer see ] unit-test
44 [ ] [ \ generic see ] unit-test
46 [ ] [ \ duplex-stream see ] unit-test
48 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
49 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
52 100 \ dup <array> unparse-short
56 : foo ( a -- b ) dup * ; inline
58 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
59 [ [ \ foo see ] with-string-writer ] unit-test
61 : bar ( x -- y ) 2 + ;
63 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
64 [ [ \ bar see ] with-string-writer ] unit-test
89 \ blah f "inferred-effect" set-word-prop
90 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
93 : check-see ( expect name -- )
98 [ parse-fresh drop ] with-compilation-unit
100 "prettyprint.tests" lookup see
101 ] with-string-writer "\n" split but-last
105 GENERIC: method-layout
107 M: complex method-layout
108 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
111 M: fixnum method-layout ;
113 M: integer method-layout ;
115 M: object method-layout ;
119 "USING: math prettyprint.tests ;"
120 "M: complex method-layout"
121 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
124 "USING: math prettyprint.tests ;"
125 "M: fixnum method-layout ;"
127 "USING: math prettyprint.tests ;"
128 "M: integer method-layout ;"
130 "USING: kernel prettyprint.tests ;"
131 "M: object method-layout ;"
135 [ \ method-layout see-methods ] with-string-writer "\n" split
140 "USING: kernel math sequences strings ;"
141 "IN: prettyprint.tests"
142 ": soft-break-layout ( x y -- ? )"
144 " over hashcode over hashcode number="
145 " [ sequence= ] [ 2drop f ] if"
146 " ] [ 2drop f ] if ;"
150 "soft-break-layout" soft-break-test check-see
153 DEFER: parse-error-file
155 : another-soft-break-test
157 "USING: make sequences ;"
158 "IN: prettyprint.tests"
159 ": another-soft-break-layout ( node -- quot )"
161 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
165 "another-soft-break-layout" another-soft-break-test
171 "USING: accessors debugger io kernel ;"
172 "IN: prettyprint.tests"
173 ": string-layout-test ( error -- )"
174 " \"Expected \" write dup want>> expected>string write"
175 " \" but got \" write got>> expected>string print ;"
180 "string-layout-test" string-layout check-see
183 ! Define dummy words for the below...
184 : <NSRect> ( a b c d -- e ) ;
185 : <PixelFormat> ( -- fmt ) ;
188 \ send soft "break-after" set-word-prop
190 : final-soft-break-test
192 "USING: kernel sequences ;"
193 "IN: prettyprint.tests"
194 ": final-soft-break-layout ( class dim -- view )"
195 " [ \"alloc\" send 0 0 ] dip first2 <NSRect>"
196 " <PixelFormat> \"initWithFrame:pixelFormat:\" send"
197 " dup 1 \"setPostsBoundsChangedNotifications:\" send"
198 " dup 1 \"setPostsFrameChangedNotifications:\" send ;"
202 "final-soft-break-layout" final-soft-break-test check-see
207 "USING: arrays combinators continuations kernel sequences ;"
208 "IN: prettyprint.tests"
209 ": narrow-layout ( obj -- )"
211 " { [ dup continuation? ] [ append ] }"
212 " { [ dup not ] [ drop reverse ] }"
213 " { [ dup pair? ] [ delete ] }"
218 "narrow-layout" narrow-test check-see
221 : another-narrow-test
223 "IN: prettyprint.tests"
224 ": another-narrow-layout ( -- obj )"
237 "another-narrow-layout" another-narrow-test check-see
240 IN: prettyprint.tests
241 TUPLE: class-see-layout ;
243 IN: prettyprint.tests
244 GENERIC: class-see-layout ( x -- y )
246 USING: prettyprint.tests ;
247 M: class-see-layout class-see-layout ;
251 "IN: prettyprint.tests"
252 "TUPLE: class-see-layout ;"
254 "IN: prettyprint.tests"
255 "GENERIC: class-see-layout ( x -- y )"
259 [ \ class-see-layout see ] with-string-writer "\n" split
264 "USING: prettyprint.tests ;"
265 "M: class-see-layout class-see-layout ;"
269 [ \ class-see-layout see-methods ] with-string-writer "\n" split
272 [ ] [ \ 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 GENERIC: generic-see-test-with-f ( obj -- obj )
300 M: f generic-see-test-with-f ;
302 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
303 [ { POSTPONE: f generic-see-test-with-f } see ] with-string-writer
306 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
307 [ \ f \ generic-see-test-with-f method see ] with-string-writer
310 PREDICATE: predicate-see-test < integer even? ;
312 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
313 [ \ predicate-see-test see ] with-string-writer
316 INTERSECTION: intersection-see-test sequence number ;
318 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
319 [ \ intersection-see-test see ] with-string-writer
322 [ ] [ \ compose see ] unit-test
323 [ ] [ \ curry see ] unit-test
325 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
327 TUPLE: started-out-hustlin' ;
329 GENERIC: ended-up-ballin'
331 M: started-out-hustlin' ended-up-ballin' ; inline
333 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
334 [ { started-out-hustlin' ended-up-ballin' } see ] with-string-writer