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.continuations
6 tools.continuations.private eval accessors make vocabs.parser see
10 [ "4" ] [ 4 unparse ] unit-test
11 [ "1.0" ] [ 1.0 unparse ] unit-test
12 [ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
14 [ "+" ] [ \ + unparse ] unit-test
16 [ "\\ +" ] [ [ \ + ] first unparse ] unit-test
18 [ "{ }" ] [ { } unparse ] unit-test
20 [ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
22 [ "\"hello\\\\backslash\"" ]
23 [ "hello\\backslash" unparse ]
27 ! [ "\u123456" unparse ]
34 [ "f" ] [ f unparse ] unit-test
35 [ "t" ] [ t unparse ] unit-test
37 [ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
39 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
41 [ ] [ \ fixnum see ] unit-test
43 [ ] [ \ integer see ] unit-test
45 [ ] [ \ generic see ] unit-test
47 [ ] [ \ duplex-stream see ] unit-test
49 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
50 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
53 100 \ dup <array> unparse-short
57 : foo ( a -- b ) dup * ; inline
59 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
60 [ [ \ foo see ] with-string-writer ] unit-test
62 : bar ( x -- y ) 2 + ;
64 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
65 [ [ \ bar see ] with-string-writer ] unit-test
67 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
90 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
93 : check-see ( expect name -- ? )
96 [ parse-fresh drop ] with-compilation-unit
98 "prettyprint.tests" lookup see
99 ] with-string-writer "\n" split but-last
101 ] with-interactive-vocabs ;
103 GENERIC: method-layout ( a -- b )
105 M: complex method-layout
107 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
110 M: fixnum method-layout ;
112 M: integer method-layout ;
114 M: object method-layout ;
118 "USING: kernel math prettyprint.tests ;"
119 "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
138 : soft-break-test ( -- str )
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 ( -- str )
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
169 : string-layout ( -- str )
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 : narrow-test ( -- array )
185 "USING: arrays combinators continuations kernel sequences ;"
186 "IN: prettyprint.tests"
187 ": narrow-layout ( obj1 obj2 -- obj3 )"
189 " { [ dup continuation? ] [ append ] }"
190 " { [ dup not ] [ drop reverse ] }"
191 " { [ dup pair? ] [ [ delete ] keep ] }"
196 "narrow-layout" narrow-test check-see
199 : another-narrow-test ( -- array )
201 "IN: prettyprint.tests"
202 ": another-narrow-layout ( -- obj )"
215 "another-narrow-layout" another-narrow-test check-see
218 IN: prettyprint.tests
219 TUPLE: class-see-layout ;
221 IN: prettyprint.tests
222 GENERIC: class-see-layout ( x -- y )
224 USING: prettyprint.tests ;
225 M: class-see-layout class-see-layout ;
229 "IN: prettyprint.tests"
230 "TUPLE: class-see-layout ;"
232 "IN: prettyprint.tests"
233 "GENERIC: class-see-layout ( x -- y )"
237 [ \ class-see-layout see ] with-string-writer "\n" split
242 "USING: prettyprint.tests ;"
243 "M: class-see-layout class-see-layout ;"
247 [ \ class-see-layout see-methods ] with-string-writer "\n" split
250 [ ] [ \ in>> synopsis drop ] unit-test
254 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
256 "generic-decl-test" "prettyprint.tests" lookup
257 [ see ] with-string-writer =
260 [ [ + ] ] [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
262 [ [ (step-into-execute) ] ] [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
265 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
269 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
272 GENERIC: generic-see-test-with-f ( obj -- obj )
274 M: f generic-see-test-with-f ;
276 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
277 [ M\ f generic-see-test-with-f see ] with-string-writer
280 PREDICATE: predicate-see-test < integer even? ;
282 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
283 [ \ predicate-see-test see ] with-string-writer
286 INTERSECTION: intersection-see-test sequence number ;
288 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
289 [ \ intersection-see-test see ] with-string-writer
292 [ ] [ \ compose see ] unit-test
293 [ ] [ \ curry see ] unit-test
295 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
297 TUPLE: started-out-hustlin' ;
299 GENERIC: ended-up-ballin' ( a -- b )
301 M: started-out-hustlin' ended-up-ballin' ; inline
303 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
304 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
307 TUPLE: tuple-with-declared-slot { x integer } ;
312 "IN: prettyprint.tests"
313 "TUPLE: tuple-with-declared-slot { x integer initial: 0 } ;"
317 [ \ tuple-with-declared-slot see ] with-string-writer "\n" split
320 TUPLE: tuple-with-read-only-slot { x read-only } ;
324 "IN: prettyprint.tests"
325 "TUPLE: tuple-with-read-only-slot { x read-only } ;"
329 [ \ tuple-with-read-only-slot see ] with-string-writer "\n" split
332 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
336 "IN: prettyprint.tests"
337 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
341 [ \ tuple-with-initial-slot see ] with-string-writer "\n" split
344 TUPLE: tuple-with-initial-declared-slot { x integer initial: 123 } ;
349 "IN: prettyprint.tests"
350 "TUPLE: tuple-with-initial-declared-slot"
351 " { x integer initial: 123 } ;"
355 [ \ tuple-with-initial-declared-slot see ] with-string-writer "\n" split