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 system 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
27 ! XXX: disabling on linux/x86.32
28 os linux? cpu x86.32? and [
29 { "NAN: 123" } [ NAN: 123 unparse ] unit-test
31 { "NAN: -123" } [ NAN: -123 unparse ] unit-test
33 { "+" } [ \ + unparse ] unit-test
35 { "\\ +" } [ [ \ + ] first unparse ] unit-test
37 { "{ }" } [ { } unparse ] unit-test
39 { "{ 1 2 3 }" } [ { 1 2 3 } unparse ] unit-test
41 { "\"hello\\\\backslash\"" }
42 [ "hello\\backslash" unparse ]
46 ! [ "\u123456" unparse ]
57 { "f" } [ f unparse ] unit-test
58 { "t" } [ t unparse ] unit-test
60 { "SBUF\" hello world\"" } [ SBUF" hello world" unparse ] unit-test
62 { "W{ \\ + }" } [ [ W{ \ + } ] first unparse ] unit-test
64 { } [ \ fixnum see ] unit-test
66 { } [ \ integer see ] unit-test
68 { } [ \ generic see ] unit-test
70 { } [ \ duplex-stream see ] unit-test
72 { "[ \\ + ]" } [ [ \ + ] unparse ] unit-test
73 { "[ \\ [ ]" } [ [ \ [ ] unparse ] unit-test
76 100 \ dup <array> unparse-short
80 : foo ( a -- b ) dup * ; inline
82 { "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" }
83 [ [ \ foo see ] with-string-writer ] unit-test
85 : bar ( x -- y ) 2 + ;
87 { "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" }
88 [ [ \ bar see ] with-string-writer ] unit-test
90 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
113 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
116 : check-see ( expect name -- ? )
119 [ parse-fresh drop ] with-compilation-unit
121 "prettyprint.tests" lookup-word see
122 ] with-string-writer split-lines
124 ] with-interactive-vocabs ;
126 GENERIC: method-layout ( a -- b )
128 M: complex method-layout
130 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
133 M: fixnum method-layout ;
135 M: integer method-layout ;
137 M: object method-layout ;
141 "USING: kernel math prettyprint.tests ;"
142 "M: complex method-layout"
144 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
147 "USING: math prettyprint.tests ;"
148 "M: fixnum method-layout ;"
150 "USING: math prettyprint.tests ;"
151 "M: integer method-layout ;"
153 "USING: kernel prettyprint.tests ;"
154 "M: object method-layout ;"
157 [ \ method-layout see-methods ] with-string-writer split-lines
160 : soft-break-test ( -- str )
162 "USING: kernel math sequences strings ;"
163 "IN: prettyprint.tests"
164 ": soft-break-layout ( x y -- ? )"
166 " over hashcode over hashcode number="
167 " [ sequence= ] [ 2drop f ] if"
168 " ] [ 2drop f ] if ;"
172 "soft-break-layout" soft-break-test check-see
175 DEFER: parse-error-file
177 : another-soft-break-test ( -- str )
179 "USING: make sequences ;"
180 "IN: prettyprint.tests"
181 ": another-soft-break-layout ( node -- quot )"
183 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
187 "another-soft-break-layout" another-soft-break-test
191 : string-layout ( -- str )
193 "USING: accessors debugger io kernel ;"
194 "IN: prettyprint.tests"
195 ": string-layout-test ( error -- )"
196 " \"Expected \" write dup want>> expected>string write"
197 " \" but got \" write got>> expected>string print ;"
202 "string-layout-test" string-layout check-see
205 : narrow-test ( -- array )
207 "USING: arrays combinators continuations kernel sequences ;"
208 "IN: prettyprint.tests"
209 ": narrow-layout ( obj1 obj2 -- obj3 )"
211 " { [ dup continuation? ] [ append ] }"
212 " { [ dup not ] [ drop reverse ] }"
213 " { [ dup pair? ] [ [ remove! drop ] keep ] }"
218 "narrow-layout" narrow-test check-see
221 : another-narrow-test ( -- array )
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 )"
258 [ \ class-see-layout see ] with-string-writer split-lines
263 "USING: prettyprint.tests ;"
264 "M: class-see-layout class-see-layout ;"
267 [ \ class-see-layout see-methods ] with-string-writer split-lines
270 { } [ \ in>> synopsis drop ] unit-test
274 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
276 "generic-decl-test" "prettyprint.tests" lookup-word
277 [ see ] with-string-writer =
280 { [ + ] } [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
282 { [ (step-into-execute) ] } [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
285 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
289 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
292 GENERIC: generic-see-test-with-f ( obj -- obj )
294 M: f generic-see-test-with-f ;
296 { "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" } [
297 [ M\ f generic-see-test-with-f see ] with-string-writer
300 PREDICATE: predicate-see-test < integer even? ;
302 { "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" } [
303 [ \ predicate-see-test see ] with-string-writer
306 INTERSECTION: intersection-see-test sequence number ;
308 { "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" } [
309 [ \ intersection-see-test see ] with-string-writer
312 { } [ \ compose see ] unit-test
313 { } [ \ curry see ] unit-test
315 { "POSTPONE: [" } [ \ [ unparse ] unit-test
317 TUPLE: started-out-hustlin' ;
319 GENERIC: ended-up-ballin' ( a -- b )
321 M: started-out-hustlin' ended-up-ballin' ; inline
323 { "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" } [
324 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
327 TUPLE: tuple-with-declared-slot { x integer } ;
332 "IN: prettyprint.tests"
333 "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 } ;"
347 [ \ tuple-with-read-only-slot see ] with-string-writer split-lines
350 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
354 "IN: prettyprint.tests"
355 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
358 [ \ tuple-with-initial-slot see ] with-string-writer split-lines
361 TUPLE: tuple-with-initial-declared-slot { x integer initial: 123 } ;
366 "IN: prettyprint.tests"
367 "TUPLE: tuple-with-initial-declared-slot"
368 " { x integer initial: 123 } ;"
371 [ \ tuple-with-initial-declared-slot see ] with-string-writer split-lines
374 TUPLE: final-tuple ; final
378 "IN: prettyprint.tests"
379 "TUPLE: final-tuple ; final"
382 [ \ final-tuple see ] with-string-writer split-lines
385 { "H{ { 1 2 } }\n" } [ [ H{ { 1 2 } } short. ] with-string-writer ] unit-test
387 { "H{ { 1 ~array~ } }\n" } [ [ H{ { 1 { 2 } } } short. ] with-string-writer ] unit-test
389 { "{ ~array~ }\n" } [ [ { { 1 2 } } short. ] with-string-writer ] unit-test
391 { "{ { 1 2 } }\n" } [ [ [ { { 1 2 } } short. ] without-limits ] with-string-writer ] unit-test
393 { "{ ~array~ }\n" } [ [ [ { { 1 2 } } . ] with-short-limits ] 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