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 [ 2 number-base [ 8.0 unparse ] with-variable ] [ unsupported-number-base? ] must-fail-with
19 [ 8 number-base [ 8.0 unparse ] with-variable ] [ unsupported-number-base? ] must-fail-with
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 ]
47 { "f" } [ f unparse ] unit-test
48 { "t" } [ t unparse ] unit-test
50 { "SBUF\" hello world\"" } [ SBUF" hello world" unparse ] unit-test
52 { "W{ \\ + }" } [ [ W{ \ + } ] first unparse ] unit-test
54 { } [ \ fixnum see ] unit-test
56 { } [ \ integer see ] unit-test
58 { } [ \ generic see ] unit-test
60 { } [ \ duplex-stream see ] unit-test
62 { "[ \\ + ]" } [ [ \ + ] unparse ] unit-test
63 { "[ \\ [ ]" } [ [ \ [ ] unparse ] unit-test
66 100 \ dup <array> unparse-short
70 : foo ( a -- b ) dup * ; inline
72 { "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" }
73 [ [ \ foo see ] with-string-writer ] unit-test
75 : bar ( x -- y ) 2 + ;
77 { "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" }
78 [ [ \ bar see ] with-string-writer ] unit-test
80 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
103 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
106 : check-see ( expect name -- ? )
109 [ parse-fresh drop ] with-compilation-unit
111 "prettyprint.tests" lookup-word see
112 ] with-string-writer "\n" split but-last
114 ] with-interactive-vocabs ;
116 GENERIC: method-layout ( a -- b )
118 M: complex method-layout
120 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
123 M: fixnum method-layout ;
125 M: integer method-layout ;
127 M: object method-layout ;
131 "USING: kernel math prettyprint.tests ;"
132 "M: complex method-layout"
134 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
137 "USING: math prettyprint.tests ;"
138 "M: fixnum method-layout ;"
140 "USING: math prettyprint.tests ;"
141 "M: integer method-layout ;"
143 "USING: kernel prettyprint.tests ;"
144 "M: object method-layout ;"
148 [ \ method-layout see-methods ] with-string-writer "\n" split
151 : soft-break-test ( -- str )
153 "USING: kernel math sequences strings ;"
154 "IN: prettyprint.tests"
155 ": soft-break-layout ( x y -- ? )"
157 " over hashcode over hashcode number="
158 " [ sequence= ] [ 2drop f ] if"
159 " ] [ 2drop f ] if ;"
163 "soft-break-layout" soft-break-test check-see
166 DEFER: parse-error-file
168 : another-soft-break-test ( -- str )
170 "USING: make sequences ;"
171 "IN: prettyprint.tests"
172 ": another-soft-break-layout ( node -- quot )"
174 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
178 "another-soft-break-layout" another-soft-break-test
182 : string-layout ( -- str )
184 "USING: accessors debugger io kernel ;"
185 "IN: prettyprint.tests"
186 ": string-layout-test ( error -- )"
187 " \"Expected \" write dup want>> expected>string write"
188 " \" but got \" write got>> expected>string print ;"
193 "string-layout-test" string-layout check-see
196 : narrow-test ( -- array )
198 "USING: arrays combinators continuations kernel sequences ;"
199 "IN: prettyprint.tests"
200 ": narrow-layout ( obj1 obj2 -- obj3 )"
202 " { [ dup continuation? ] [ append ] }"
203 " { [ dup not ] [ drop reverse ] }"
204 " { [ dup pair? ] [ [ remove! drop ] keep ] }"
209 "narrow-layout" narrow-test check-see
212 : another-narrow-test ( -- array )
214 "IN: prettyprint.tests"
215 ": another-narrow-layout ( -- obj )"
228 "another-narrow-layout" another-narrow-test check-see
231 IN: prettyprint.tests
232 TUPLE: class-see-layout ;
234 IN: prettyprint.tests
235 GENERIC: class-see-layout ( x -- y )
237 USING: prettyprint.tests ;
238 M: class-see-layout class-see-layout ;
242 "IN: prettyprint.tests"
243 "TUPLE: class-see-layout ;"
245 "IN: prettyprint.tests"
246 "GENERIC: class-see-layout ( x -- y )"
250 [ \ class-see-layout see ] with-string-writer "\n" split
255 "USING: prettyprint.tests ;"
256 "M: class-see-layout class-see-layout ;"
260 [ \ class-see-layout see-methods ] with-string-writer "\n" split
263 { } [ \ in>> synopsis drop ] unit-test
267 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
269 "generic-decl-test" "prettyprint.tests" lookup-word
270 [ see ] with-string-writer =
273 { [ + ] } [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
275 { [ (step-into-execute) ] } [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
278 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
282 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
285 GENERIC: generic-see-test-with-f ( obj -- obj )
287 M: f generic-see-test-with-f ;
289 { "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" } [
290 [ M\ f generic-see-test-with-f see ] with-string-writer
293 PREDICATE: predicate-see-test < integer even? ;
295 { "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" } [
296 [ \ predicate-see-test see ] with-string-writer
299 INTERSECTION: intersection-see-test sequence number ;
301 { "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" } [
302 [ \ intersection-see-test see ] with-string-writer
305 { } [ \ compose see ] unit-test
306 { } [ \ curry see ] unit-test
308 { "POSTPONE: [" } [ \ [ unparse ] unit-test
310 TUPLE: started-out-hustlin' ;
312 GENERIC: ended-up-ballin' ( a -- b )
314 M: started-out-hustlin' ended-up-ballin' ; inline
316 { "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" } [
317 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer
320 TUPLE: tuple-with-declared-slot { x integer } ;
325 "IN: prettyprint.tests"
326 "TUPLE: tuple-with-declared-slot { x integer initial: 0 } ;"
330 [ \ tuple-with-declared-slot see ] with-string-writer "\n" split
333 TUPLE: tuple-with-read-only-slot { x read-only } ;
337 "IN: prettyprint.tests"
338 "TUPLE: tuple-with-read-only-slot { x read-only } ;"
342 [ \ tuple-with-read-only-slot see ] with-string-writer "\n" split
345 TUPLE: tuple-with-initial-slot { x initial: 123 } ;
349 "IN: prettyprint.tests"
350 "TUPLE: tuple-with-initial-slot { x initial: 123 } ;"
354 [ \ tuple-with-initial-slot see ] with-string-writer "\n" split
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 } ;"
368 [ \ tuple-with-initial-declared-slot see ] with-string-writer "\n" split
371 TUPLE: final-tuple ; final
375 "IN: prettyprint.tests"
376 "TUPLE: final-tuple ; final"
380 [ \ final-tuple see ] with-string-writer "\n" split
383 { "H{ { 1 2 } }\n" } [ [ H{ { 1 2 } } short. ] with-string-writer ] unit-test
385 { "H{ { 1 ~array~ } }\n" } [ [ H{ { 1 { 2 } } } short. ] with-string-writer ] unit-test
387 { "{ ~array~ }\n" } [ [ { { 1 2 } } short. ] with-string-writer ] unit-test
389 { "H{ { 1 { 2 3 } } }\n" } [
391 [ H{ { 1 { 2 3 } } } . ] with-string-writer
395 { "maybe{ integer }\n" } [ [ maybe{ integer } . ] with-string-writer ] unit-test
397 { "maybe{ bob }\n" } [ [ maybe{ bob } . ] with-string-writer ] unit-test
398 { "maybe{ word }\n" } [ [ maybe{ word } . ] with-string-writer ] unit-test
401 GENERIC: harhar ( obj -- obj )
402 M: maybe{ har } harhar ;
403 M: integer harhar M\ integer harhar drop ;
405 "USING: prettyprint.tests ;
406 M: maybe{ har } harhar ;
408 USING: kernel math prettyprint.tests ;
409 M: integer harhar M\\ integer harhar drop ;\n"
411 [ \ harhar see-methods ] with-string-writer
414 TUPLE: mo { a union{ float integer } } ;
415 TUPLE: fo { a intersection{ fixnum integer } } ;
419 IN: prettyprint.tests
420 TUPLE: mo { a union{ integer float } initial: 0 } ;
423 [ \ mo see ] with-string-writer
428 IN: prettyprint.tests
429 TUPLE: fo { a intersection{ integer fixnum } initial: 0 } ;
432 [ \ fo see ] with-string-writer
436 "union{ intersection{ string hashtable } union{ integer float } }\n"
437 } [ [ union{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
441 intersection{ string hashtable }
442 union{ integer float }
445 } [ [ intersection{ union{ float integer } intersection{ string hashtable } } . ] with-string-writer ] unit-test
448 "maybe{ union{ integer float } }\n"
450 [ maybe{ union{ float integer } } . ] with-string-writer
454 "maybe{ maybe{ integer } }\n"
456 [ maybe{ maybe{ integer } } . ] with-string-writer
459 { "{ 0 1 2 3 4 }" } [
460 [ 5 length-limit [ 5 iota >array pprint ] with-variable ]
464 { "{ 0 1 2 3 ~2 more~ }" } [
465 [ 5 length-limit [ 6 iota >array pprint ] with-variable ]
469 : margin-test ( number-of-'a's -- str )
471 [ CHAR: a <string> text "b" text ] with-pprint
472 ] with-string-writer ;
475 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
476 } [ margin get 3 - margin-test ] unit-test
479 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b"
480 } [ margin get 2 - margin-test ] unit-test
483 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
485 } [ margin get 1 - margin-test ] unit-test