1 USING: accessors arrays classes.intersection classes.maybe
2 classes.union compiler.units continuations definitions effects
3 eval generic generic.standard hashtables io io.streams.duplex
4 io.streams.string kernel listener make math namespaces parser
5 prettyprint prettyprint.config prettyprint.private
6 prettyprint.sections see sequences splitting
7 strings tools.continuations tools.continuations.private
8 tools.test vectors vocabs.parser words ;
11 [ "4" ] [ 4 unparse ] unit-test
12 [ "4096" ] [ 4096 unparse ] unit-test
13 [ "0b1000000000000" ] [ 2 number-base [ 4096 unparse ] with-variable ] unit-test
14 [ "0o10000" ] [ 8 number-base [ 4096 unparse ] with-variable ] unit-test
15 [ "0x1000" ] [ 16 number-base [ 4096 unparse ] with-variable ] unit-test
16 [ "1.0" ] [ 1.0 unparse ] unit-test
17 [ "8.0" ] [ 8.0 unparse ] unit-test
18 [ "8.0" ] [ 2 number-base [ 8.0 unparse ] with-variable ] unit-test
19 [ "8.0" ] [ 8 number-base [ 8.0 unparse ] with-variable ] unit-test
20 [ "0x1.0p3" ] [ 16 number-base [ 8.0 unparse ] with-variable ] unit-test
21 [ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
23 [ "+" ] [ \ + unparse ] unit-test
25 [ "\\ +" ] [ [ \ + ] first unparse ] unit-test
27 [ "{ }" ] [ { } unparse ] unit-test
29 [ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
31 [ "\"hello\\\\backslash\"" ]
32 [ "hello\\backslash" unparse ]
36 ! [ "\u123456" unparse ]
43 [ "f" ] [ f unparse ] unit-test
44 [ "t" ] [ t unparse ] unit-test
46 [ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
48 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
50 [ ] [ \ fixnum see ] unit-test
52 [ ] [ \ integer see ] unit-test
54 [ ] [ \ generic see ] unit-test
56 [ ] [ \ duplex-stream see ] unit-test
58 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
59 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
62 100 \ dup <array> unparse-short
66 : foo ( a -- b ) dup * ; inline
68 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
69 [ [ \ foo see ] with-string-writer ] unit-test
71 : bar ( x -- y ) 2 + ;
73 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
74 [ [ \ bar see ] with-string-writer ] unit-test
76 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
99 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
102 : check-see ( expect name -- ? )
105 [ parse-fresh drop ] with-compilation-unit
107 "prettyprint.tests" lookup-word see
108 ] with-string-writer "\n" split but-last
110 ] with-interactive-vocabs ;
112 GENERIC: method-layout ( a -- b )
114 M: complex method-layout
116 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
119 M: fixnum method-layout ;
121 M: integer method-layout ;
123 M: object method-layout ;
127 "USING: kernel math prettyprint.tests ;"
128 "M: complex method-layout"
130 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
133 "USING: math prettyprint.tests ;"
134 "M: fixnum method-layout ;"
136 "USING: math prettyprint.tests ;"
137 "M: integer method-layout ;"
139 "USING: kernel prettyprint.tests ;"
140 "M: object method-layout ;"
144 [ \ method-layout see-methods ] with-string-writer "\n" split
147 : soft-break-test ( -- str )
149 "USING: kernel math sequences strings ;"
150 "IN: prettyprint.tests"
151 ": soft-break-layout ( x y -- ? )"
153 " over hashcode over hashcode number="
154 " [ sequence= ] [ 2drop f ] if"
155 " ] [ 2drop f ] if ;"
159 "soft-break-layout" soft-break-test check-see
162 DEFER: parse-error-file
164 : another-soft-break-test ( -- str )
166 "USING: make sequences ;"
167 "IN: prettyprint.tests"
168 ": another-soft-break-layout ( node -- quot )"
170 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
174 "another-soft-break-layout" another-soft-break-test
178 : string-layout ( -- str )
180 "USING: accessors debugger io kernel ;"
181 "IN: prettyprint.tests"
182 ": string-layout-test ( error -- )"
183 " \"Expected \" write dup want>> expected>string write"
184 " \" but got \" write got>> expected>string print ;"
189 "string-layout-test" string-layout check-see
192 : narrow-test ( -- array )
194 "USING: arrays combinators continuations kernel sequences ;"
195 "IN: prettyprint.tests"
196 ": narrow-layout ( obj1 obj2 -- obj3 )"
198 " { [ dup continuation? ] [ append ] }"
199 " { [ dup not ] [ drop reverse ] }"
200 " { [ dup pair? ] [ [ remove! drop ] keep ] }"
205 "narrow-layout" narrow-test check-see
208 : another-narrow-test ( -- array )
210 "IN: prettyprint.tests"
211 ": another-narrow-layout ( -- obj )"
224 "another-narrow-layout" another-narrow-test check-see
227 IN: prettyprint.tests
228 TUPLE: class-see-layout ;
230 IN: prettyprint.tests
231 GENERIC: class-see-layout ( x -- y )
233 USING: prettyprint.tests ;
234 M: class-see-layout class-see-layout ;
238 "IN: prettyprint.tests"
239 "TUPLE: class-see-layout ;"
241 "IN: prettyprint.tests"
242 "GENERIC: class-see-layout ( x -- y )"
246 [ \ class-see-layout see ] with-string-writer "\n" split
251 "USING: prettyprint.tests ;"
252 "M: class-see-layout class-see-layout ;"
256 [ \ class-see-layout see-methods ] with-string-writer "\n" split
259 [ ] [ \ in>> synopsis drop ] unit-test
263 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
265 "generic-decl-test" "prettyprint.tests" lookup-word
266 [ see ] with-string-writer =
269 [ [ + ] ] [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
271 [ [ (step-into-execute) ] ] [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
274 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
278 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
281 GENERIC: generic-see-test-with-f ( obj -- obj )
283 M: f generic-see-test-with-f ;
285 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
286 [ M\ f generic-see-test-with-f see ] with-string-writer
289 PREDICATE: predicate-see-test < integer even? ;
291 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
292 [ \ predicate-see-test see ] with-string-writer
295 INTERSECTION: intersection-see-test sequence number ;
297 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
298 [ \ intersection-see-test see ] with-string-writer
301 [ ] [ \ compose see ] unit-test
302 [ ] [ \ curry see ] unit-test
304 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
306 TUPLE: started-out-hustlin' ;
308 GENERIC: ended-up-ballin' ( a -- b )
310 M: started-out-hustlin' ended-up-ballin' ; inline
312 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
313 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
316 TUPLE: tuple-with-declared-slot { x integer } ;
321 "IN: prettyprint.tests"
322 "TUPLE: tuple-with-declared-slot { x integer initial: 0 } ;"
326 [ \ tuple-with-declared-slot see ] with-string-writer "\n" split
329 TUPLE: tuple-with-read-only-slot { x read-only } ;
333 "IN: prettyprint.tests"
334 "TUPLE: tuple-with-read-only-slot { x read-only } ;"
338 [ \ tuple-with-read-only-slot see ] with-string-writer "\n" split
341 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
345 "IN: prettyprint.tests"
346 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
350 [ \ tuple-with-initial-slot see ] with-string-writer "\n" split
353 TUPLE: tuple-with-initial-declared-slot { x integer initial: 123 } ;
358 "IN: prettyprint.tests"
359 "TUPLE: tuple-with-initial-declared-slot"
360 " { x integer initial: 123 } ;"
364 [ \ tuple-with-initial-declared-slot see ] with-string-writer "\n" split
367 TUPLE: final-tuple ; final
371 "IN: prettyprint.tests"
372 "TUPLE: final-tuple ; final"
376 [ \ final-tuple see ] with-string-writer "\n" split
379 [ "H{ { 1 2 } }\n" ] [ [ H{ { 1 2 } } short. ] with-string-writer ] unit-test
381 [ "H{ { 1 ~array~ } }\n" ] [ [ H{ { 1 { 2 } } } short. ] with-string-writer ] unit-test
383 [ "{ ~array~ }\n" ] [ [ { { 1 2 } } short. ] with-string-writer ] unit-test
385 [ "H{ { 1 { 2 3 } } }\n" ] [
387 [ H{ { 1 { 2 3 } } } . ] with-string-writer
391 [ "maybe: integer\n" ] [ [ maybe: integer . ] with-string-writer ] unit-test
393 [ "maybe: bob\n" ] [ [ maybe: bob . ] with-string-writer ] unit-test
394 [ "maybe: word\n" ] [ [ maybe: word . ] with-string-writer ] unit-test
397 GENERIC: harhar ( obj -- obj )
398 M: maybe: har harhar ;
399 M: integer harhar M\ integer harhar drop ;
401 """USING: prettyprint.tests ;
402 M: maybe: har harhar ;
404 USING: kernel math prettyprint.tests ;
405 M: integer harhar M\\ integer harhar drop ;\n"""
407 [ \ harhar see-methods ] with-string-writer
410 TUPLE: mo { a union{ float integer } } ;
411 TUPLE: fo { a intersection{ fixnum integer } } ;
415 IN: prettyprint.tests
416 TUPLE: mo { a union{ float integer } initial: 0 } ;
419 [ \ mo see ] with-string-writer
424 IN: prettyprint.tests
425 TUPLE: fo { a intersection{ fixnum integer } initial: 0 } ;
428 [ \ fo see ] with-string-writer
433 union{ float integer }
434 intersection{ string hashtable }
437 ] [ [ union{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
441 union{ float integer }
442 intersection{ string hashtable }
445 ] [ [ intersection{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
448 """maybe: union{ float integer }\n"""
450 [ maybe: union{ float integer } . ] with-string-writer
454 """maybe: maybe: integer\n"""
456 [ maybe: maybe: integer . ] with-string-writer