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.backend 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 { "0b1.001p4" } [ 2 number-base [ 18.0 unparse ] with-variable ] unit-test
19 { "0o1.1p4" } [ 8 number-base [ 18.0 unparse ] with-variable ] unit-test
20 { "0x1.2p4" } [ 16 number-base [ 18.0 unparse ] with-variable ] unit-test
21 { "1267650600228229401496703205376" } [ 1 100 shift unparse ] unit-test
22 { "1/0." } [ 1/0. unparse ] unit-test
23 { "-1/0." } [ -1/0. unparse ] unit-test
24 { "0/0." } [ 0/0. unparse ] unit-test
25 { "-0/0." } [ -0/0. unparse ] unit-test
26 { "NAN: 123" } [ NAN: 123 unparse ] unit-test
27 { "NAN: -123" } [ NAN: -123 unparse ] unit-test
29 { "+" } [ \ + unparse ] unit-test
31 { "\\ +" } [ [ \ + ] first unparse ] unit-test
33 { "{ }" } [ { } unparse ] unit-test
35 { "{ 1 2 3 }" } [ { 1 2 3 } unparse ] unit-test
37 { "\"hello\\\\backslash\"" }
38 [ "hello\\backslash" unparse ]
42 ! [ "\u123456" unparse ]
53 { "f" } [ f unparse ] unit-test
54 { "t" } [ t unparse ] unit-test
56 { "SBUF\" hello world\"" } [ SBUF" hello world" unparse ] unit-test
58 { "W{ \\ + }" } [ [ W{ \ + } ] first unparse ] unit-test
60 { } [ \ fixnum see ] unit-test
62 { } [ \ integer see ] unit-test
64 { } [ \ generic see ] unit-test
66 { } [ \ duplex-stream see ] unit-test
68 { "[ \\ + ]" } [ [ \ + ] unparse ] unit-test
69 { "[ \\ [ ]" } [ [ \ [ ] unparse ] unit-test
72 100 \ dup <array> unparse-short
76 : foo ( a -- b ) dup * ; inline
78 { "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" }
79 [ [ \ foo see ] with-string-writer ] unit-test
81 : bar ( x -- y ) 2 + ;
83 { "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" }
84 [ [ \ bar see ] with-string-writer ] unit-test
86 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
109 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
112 : check-see ( expect name -- ? )
115 [ parse-fresh drop ] with-compilation-unit
117 "prettyprint.tests" lookup-word see
118 ] with-string-writer split-lines but-last
120 ] with-interactive-vocabs ;
122 GENERIC: method-layout ( a -- b )
124 M: complex method-layout
126 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
129 M: fixnum method-layout ;
131 M: integer method-layout ;
133 M: object method-layout ;
137 "USING: kernel math prettyprint.tests ;"
138 "M: complex method-layout"
140 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
143 "USING: math prettyprint.tests ;"
144 "M: fixnum method-layout ;"
146 "USING: math prettyprint.tests ;"
147 "M: integer method-layout ;"
149 "USING: kernel prettyprint.tests ;"
150 "M: object method-layout ;"
154 [ \ method-layout see-methods ] with-string-writer split-lines
157 : soft-break-test ( -- str )
159 "USING: kernel math sequences strings ;"
160 "IN: prettyprint.tests"
161 ": soft-break-layout ( x y -- ? )"
163 " over hashcode over hashcode number="
164 " [ sequence= ] [ 2drop f ] if"
165 " ] [ 2drop f ] if ;"
169 "soft-break-layout" soft-break-test check-see
172 DEFER: parse-error-file
174 : another-soft-break-test ( -- str )
176 "USING: make sequences ;"
177 "IN: prettyprint.tests"
178 ": another-soft-break-layout ( node -- quot )"
180 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
184 "another-soft-break-layout" another-soft-break-test
188 : string-layout ( -- str )
190 "USING: accessors debugger io kernel ;"
191 "IN: prettyprint.tests"
192 ": string-layout-test ( error -- )"
193 " \"Expected \" write dup want>> expected>string write"
194 " \" but got \" write got>> expected>string print ;"
199 "string-layout-test" string-layout check-see
202 : narrow-test ( -- array )
204 "USING: arrays combinators continuations kernel sequences ;"
205 "IN: prettyprint.tests"
206 ": narrow-layout ( obj1 obj2 -- obj3 )"
208 " { [ dup continuation? ] [ append ] }"
209 " { [ dup not ] [ drop reverse ] }"
210 " { [ dup pair? ] [ [ remove! drop ] keep ] }"
215 "narrow-layout" narrow-test check-see
218 : another-narrow-test ( -- array )
220 "IN: prettyprint.tests"
221 ": another-narrow-layout ( -- obj )"
234 "another-narrow-layout" another-narrow-test check-see
237 IN: prettyprint.tests
238 TUPLE: class-see-layout ;
240 IN: prettyprint.tests
241 GENERIC: class-see-layout ( x -- y )
243 USING: prettyprint.tests ;
244 M: class-see-layout class-see-layout ;
248 "IN: prettyprint.tests"
249 "TUPLE: class-see-layout ;"
251 "IN: prettyprint.tests"
252 "GENERIC: class-see-layout ( x -- y )"
256 [ \ class-see-layout see ] with-string-writer split-lines
261 "USING: prettyprint.tests ;"
262 "M: class-see-layout class-see-layout ;"
266 [ \ class-see-layout see-methods ] with-string-writer split-lines
269 { } [ \ in>> synopsis drop ] unit-test
273 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
275 "generic-decl-test" "prettyprint.tests" lookup-word
276 [ see ] with-string-writer =
279 { [ + ] } [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
281 { [ (step-into-execute) ] } [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
284 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
288 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
291 GENERIC: generic-see-test-with-f ( obj -- obj )
293 M: f generic-see-test-with-f ;
295 { "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" } [
296 [ M\ f generic-see-test-with-f see ] with-string-writer
299 PREDICATE: predicate-see-test < integer even? ;
301 { "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" } [
302 [ \ predicate-see-test see ] with-string-writer
305 INTERSECTION: intersection-see-test sequence number ;
307 { "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" } [
308 [ \ intersection-see-test see ] with-string-writer
311 { } [ \ compose see ] unit-test
312 { } [ \ curry see ] unit-test
314 { "POSTPONE: [" } [ \ [ unparse ] unit-test
316 TUPLE: started-out-hustlin' ;
318 GENERIC: ended-up-ballin' ( a -- b )
320 M: started-out-hustlin' ended-up-ballin' ; inline
322 { "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" } [
323 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
326 TUPLE: tuple-with-declared-slot { x integer } ;
331 "IN: prettyprint.tests"
332 "TUPLE: tuple-with-declared-slot { x integer initial: 0 } ;"
336 [ \ tuple-with-declared-slot see ] with-string-writer split-lines
339 TUPLE: tuple-with-read-only-slot { x read-only } ;
343 "IN: prettyprint.tests"
344 "TUPLE: tuple-with-read-only-slot { x read-only } ;"
348 [ \ tuple-with-read-only-slot see ] with-string-writer split-lines
351 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
355 "IN: prettyprint.tests"
356 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
360 [ \ tuple-with-initial-slot see ] with-string-writer split-lines
363 TUPLE: tuple-with-initial-declared-slot { x integer initial: 123 } ;
368 "IN: prettyprint.tests"
369 "TUPLE: tuple-with-initial-declared-slot"
370 " { x integer initial: 123 } ;"
374 [ \ tuple-with-initial-declared-slot see ] with-string-writer split-lines
377 TUPLE: final-tuple ; final
381 "IN: prettyprint.tests"
382 "TUPLE: final-tuple ; final"
386 [ \ final-tuple see ] with-string-writer split-lines
389 { "H{ { 1 2 } }\n" } [ [ H{ { 1 2 } } short. ] with-string-writer ] unit-test
391 { "H{ { 1 ~array~ } }\n" } [ [ H{ { 1 { 2 } } } short. ] with-string-writer ] unit-test
393 { "{ ~array~ }\n" } [ [ { { 1 2 } } short. ] with-string-writer ] unit-test
395 { "H{ { 1 { 2 3 } } }\n" } [
397 [ H{ { 1 { 2 3 } } } . ] with-string-writer
401 { "maybe{ integer }\n" } [ [ maybe{ integer } . ] with-string-writer ] unit-test
403 { "maybe{ bob }\n" } [ [ maybe{ bob } . ] with-string-writer ] unit-test
404 { "maybe{ word }\n" } [ [ maybe{ word } . ] with-string-writer ] unit-test
407 GENERIC: harhar ( obj -- obj )
408 M: maybe{ har } harhar ;
409 M: integer harhar M\ integer harhar drop ;
411 "USING: prettyprint.tests ;
412 M: maybe{ har } harhar ;
414 USING: kernel math prettyprint.tests ;
415 M: integer harhar M\\ integer harhar drop ;\n"
417 [ \ harhar see-methods ] with-string-writer
420 TUPLE: mo { a union{ float integer } } ;
421 TUPLE: fo { a intersection{ fixnum integer } } ;
425 IN: prettyprint.tests
426 TUPLE: mo { a union{ integer float } initial: 0 } ;
429 [ \ mo see ] with-string-writer
434 IN: prettyprint.tests
435 TUPLE: fo { a intersection{ integer fixnum } initial: 0 } ;
438 [ \ fo see ] with-string-writer
442 "union{ intersection{ string hashtable } union{ integer float } }\n"
443 } [ [ union{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
447 intersection{ string hashtable }
448 union{ integer float }
451 } [ [ intersection{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
454 "maybe{ union{ integer float } }\n"
456 [ maybe{ union{ float integer } } . ] with-string-writer
460 "maybe{ maybe{ integer } }\n"
462 [ maybe{ maybe{ integer } } . ] with-string-writer
465 { "{ 0 1 2 3 4 }" } [
466 [ 5 length-limit [ 5 <iota> >array pprint ] with-variable ]
470 { "{ 0 1 2 3 ~2 more~ }" } [
471 [ 5 length-limit [ 6 <iota> >array pprint ] with-variable ]
475 : margin-test ( number-of-'a's -- str )
477 [ CHAR: a <string> text "b" text ] with-pprint
478 ] with-string-writer ;
481 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
482 } [ margin get 3 - margin-test ] unit-test
485 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
486 } [ margin get 2 - margin-test ] unit-test
489 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
491 } [ margin get 1 - margin-test ] unit-test