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
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 ;"
153 [ \ method-layout see-methods ] with-string-writer split-lines
156 : soft-break-test ( -- str )
158 "USING: kernel math sequences strings ;"
159 "IN: prettyprint.tests"
160 ": soft-break-layout ( x y -- ? )"
162 " over hashcode over hashcode number="
163 " [ sequence= ] [ 2drop f ] if"
164 " ] [ 2drop f ] if ;"
168 "soft-break-layout" soft-break-test check-see
171 DEFER: parse-error-file
173 : another-soft-break-test ( -- str )
175 "USING: make sequences ;"
176 "IN: prettyprint.tests"
177 ": another-soft-break-layout ( node -- quot )"
179 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
183 "another-soft-break-layout" another-soft-break-test
187 : string-layout ( -- str )
189 "USING: accessors debugger io kernel ;"
190 "IN: prettyprint.tests"
191 ": string-layout-test ( error -- )"
192 " \"Expected \" write dup want>> expected>string write"
193 " \" but got \" write got>> expected>string print ;"
198 "string-layout-test" string-layout check-see
201 : narrow-test ( -- array )
203 "USING: arrays combinators continuations kernel sequences ;"
204 "IN: prettyprint.tests"
205 ": narrow-layout ( obj1 obj2 -- obj3 )"
207 " { [ dup continuation? ] [ append ] }"
208 " { [ dup not ] [ drop reverse ] }"
209 " { [ dup pair? ] [ [ remove! drop ] keep ] }"
214 "narrow-layout" narrow-test check-see
217 : another-narrow-test ( -- array )
219 "IN: prettyprint.tests"
220 ": another-narrow-layout ( -- obj )"
233 "another-narrow-layout" another-narrow-test check-see
236 IN: prettyprint.tests
237 TUPLE: class-see-layout ;
239 IN: prettyprint.tests
240 GENERIC: class-see-layout ( x -- y )
242 USING: prettyprint.tests ;
243 M: class-see-layout class-see-layout ;
247 "IN: prettyprint.tests"
248 "TUPLE: class-see-layout ;"
250 "IN: prettyprint.tests"
251 "GENERIC: class-see-layout ( x -- y )"
254 [ \ class-see-layout see ] with-string-writer split-lines
259 "USING: prettyprint.tests ;"
260 "M: class-see-layout class-see-layout ;"
263 [ \ class-see-layout see-methods ] with-string-writer split-lines
266 { } [ \ in>> synopsis drop ] unit-test
270 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
272 "generic-decl-test" "prettyprint.tests" lookup-word
273 [ see ] with-string-writer =
276 { [ + ] } [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
278 { [ (step-into-execute) ] } [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
281 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
285 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
288 GENERIC: generic-see-test-with-f ( obj -- obj )
290 M: f generic-see-test-with-f ;
292 { "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" } [
293 [ M\ f generic-see-test-with-f see ] with-string-writer
296 PREDICATE: predicate-see-test < integer even? ;
298 { "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" } [
299 [ \ predicate-see-test see ] with-string-writer
302 INTERSECTION: intersection-see-test sequence number ;
304 { "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" } [
305 [ \ intersection-see-test see ] with-string-writer
308 { } [ \ compose see ] unit-test
309 { } [ \ curry see ] unit-test
311 { "POSTPONE: [" } [ \ [ unparse ] unit-test
313 TUPLE: started-out-hustlin' ;
315 GENERIC: ended-up-ballin' ( a -- b )
317 M: started-out-hustlin' ended-up-ballin' ; inline
319 { "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" } [
320 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
323 TUPLE: tuple-with-declared-slot { x integer } ;
328 "IN: prettyprint.tests"
329 "TUPLE: tuple-with-declared-slot { x integer initial: 0 } ;"
332 [ \ tuple-with-declared-slot see ] with-string-writer split-lines
335 TUPLE: tuple-with-read-only-slot { x read-only } ;
339 "IN: prettyprint.tests"
340 "TUPLE: tuple-with-read-only-slot { x read-only } ;"
343 [ \ tuple-with-read-only-slot see ] with-string-writer split-lines
346 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
350 "IN: prettyprint.tests"
351 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
354 [ \ tuple-with-initial-slot see ] with-string-writer split-lines
357 TUPLE: tuple-with-initial-declared-slot { x integer initial: 123 } ;
362 "IN: prettyprint.tests"
363 "TUPLE: tuple-with-initial-declared-slot"
364 " { x integer initial: 123 } ;"
367 [ \ tuple-with-initial-declared-slot see ] with-string-writer split-lines
370 TUPLE: final-tuple ; final
374 "IN: prettyprint.tests"
375 "TUPLE: final-tuple ; final"
378 [ \ final-tuple see ] with-string-writer split-lines
381 { "H{ { 1 2 } }\n" } [ [ H{ { 1 2 } } short. ] with-string-writer ] unit-test
383 { "H{ { 1 ~array~ } }\n" } [ [ H{ { 1 { 2 } } } short. ] with-string-writer ] unit-test
385 { "{ ~array~ }\n" } [ [ { { 1 2 } } short. ] with-string-writer ] unit-test
387 { "H{ { 1 { 2 3 } } }\n" } [
389 [ H{ { 1 { 2 3 } } } . ] with-string-writer
393 { "maybe{ integer }\n" } [ [ maybe{ integer } . ] with-string-writer ] unit-test
395 { "maybe{ bob }\n" } [ [ maybe{ bob } . ] with-string-writer ] unit-test
396 { "maybe{ word }\n" } [ [ maybe{ word } . ] with-string-writer ] unit-test
399 GENERIC: harhar ( obj -- obj )
400 M: maybe{ har } harhar ;
401 M: integer harhar M\ integer harhar drop ;
403 "USING: prettyprint.tests ;
404 M: maybe{ har } harhar ;
406 USING: kernel math prettyprint.tests ;
407 M: integer harhar M\\ integer harhar drop ;\n"
409 [ \ harhar see-methods ] with-string-writer
412 TUPLE: mo { a union{ float integer } } ;
413 TUPLE: fo { a intersection{ fixnum integer } } ;
417 IN: prettyprint.tests
418 TUPLE: mo { a union{ integer float } initial: 0 } ;
421 [ \ mo see ] with-string-writer
426 IN: prettyprint.tests
427 TUPLE: fo { a intersection{ integer fixnum } initial: 0 } ;
430 [ \ fo see ] with-string-writer
434 "union{ intersection{ string hashtable } union{ integer float } }\n"
435 } [ [ union{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
439 intersection{ string hashtable }
440 union{ integer float }
443 } [ [ intersection{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
446 "maybe{ union{ integer float } }\n"
448 [ maybe{ union{ float integer } } . ] with-string-writer
452 "maybe{ maybe{ integer } }\n"
454 [ maybe{ maybe{ integer } } . ] with-string-writer
457 { "{ 0 1 2 3 4 }" } [
458 [ 5 length-limit [ 5 <iota> >array pprint ] with-variable ]
462 { "{ 0 1 2 3 ~2 more~ }" } [
463 [ 5 length-limit [ 6 <iota> >array pprint ] with-variable ]
467 : margin-test ( number-of-'a's -- str )
469 [ CHAR: a <string> text "b" text ] with-pprint
470 ] with-string-writer ;
473 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
474 } [ margin get 3 - margin-test ] unit-test
477 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
478 } [ margin get 2 - margin-test ] unit-test
481 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
483 } [ margin get 1 - margin-test ] unit-test