1 USING: arrays definitions io.streams.string io.streams.duplex
2 kernel math namespaces parser prettyprint prettyprint.config
3 prettyprint.sections sequences tools.test vectors words
4 effects splitting generic.standard prettyprint.private
5 continuations generic compiler.units tools.walker eval
6 accessors make vocabs.parser see ;
9 [ "4" ] [ 4 unparse ] unit-test
10 [ "1.0" ] [ 1.0 unparse ] unit-test
11 [ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
13 [ "+" ] [ \ + unparse ] unit-test
15 [ "\\ +" ] [ [ \ + ] first unparse ] unit-test
17 [ "{ }" ] [ { } unparse ] unit-test
19 [ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
21 [ "\"hello\\\\backslash\"" ]
22 [ "hello\\backslash" unparse ]
26 ! [ "\u123456" unparse ]
33 [ "f" ] [ f unparse ] unit-test
34 [ "t" ] [ t unparse ] unit-test
36 [ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
38 [ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
40 [ ] [ \ fixnum see ] unit-test
42 [ ] [ \ integer see ] unit-test
44 [ ] [ \ generic see ] unit-test
46 [ ] [ \ duplex-stream see ] unit-test
48 [ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
49 [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
52 100 \ dup <array> unparse-short
56 : foo ( a -- b ) dup * ; inline
58 [ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
59 [ [ \ foo see ] with-string-writer ] unit-test
61 : bar ( x -- y ) 2 + ;
63 [ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
64 [ [ \ bar see ] with-string-writer ] unit-test
66 : blah ( a a a a a a a a a a a a a a a a a a a a -- )
89 \ blah f "inferred-effect" set-word-prop
90 [ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
93 : check-see ( expect name -- )
98 [ parse-fresh drop ] with-compilation-unit
100 "prettyprint.tests" lookup see
101 ] with-string-writer "\n" split but-last
105 GENERIC: method-layout ( a -- b )
107 M: complex method-layout
108 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
111 M: fixnum method-layout ;
113 M: integer method-layout ;
115 M: object method-layout ;
119 "USING: math prettyprint.tests ;"
120 "M: complex method-layout"
121 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
124 "USING: math prettyprint.tests ;"
125 "M: fixnum method-layout ;"
127 "USING: math prettyprint.tests ;"
128 "M: integer method-layout ;"
130 "USING: kernel prettyprint.tests ;"
131 "M: object method-layout ;"
135 [ \ method-layout see-methods ] with-string-writer "\n" split
138 : soft-break-test ( -- str )
140 "USING: kernel math sequences strings ;"
141 "IN: prettyprint.tests"
142 ": soft-break-layout ( x y -- ? )"
144 " over hashcode over hashcode number="
145 " [ sequence= ] [ 2drop f ] if"
146 " ] [ 2drop f ] if ;"
150 "soft-break-layout" soft-break-test check-see
153 DEFER: parse-error-file
155 : another-soft-break-test ( -- str )
157 "USING: make sequences ;"
158 "IN: prettyprint.tests"
159 ": another-soft-break-layout ( node -- quot )"
161 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
165 "another-soft-break-layout" another-soft-break-test
169 : string-layout ( -- str )
171 "USING: accessors debugger io kernel ;"
172 "IN: prettyprint.tests"
173 ": string-layout-test ( error -- )"
174 " \"Expected \" write dup want>> expected>string write"
175 " \" but got \" write got>> expected>string print ;"
180 "string-layout-test" string-layout check-see
183 : narrow-test ( -- str )
185 "USING: arrays combinators continuations kernel sequences ;"
186 "IN: prettyprint.tests"
187 ": narrow-layout ( obj -- )"
189 " { [ dup continuation? ] [ append ] }"
190 " { [ dup not ] [ drop reverse ] }"
191 " { [ dup pair? ] [ delete ] }"
196 "narrow-layout" narrow-test check-see
199 : another-narrow-test ( -- str )
201 "IN: prettyprint.tests"
202 ": another-narrow-layout ( -- obj )"
215 "another-narrow-layout" another-narrow-test check-see
218 IN: prettyprint.tests
219 TUPLE: class-see-layout ;
221 IN: prettyprint.tests
222 GENERIC: class-see-layout ( x -- y )
224 USING: prettyprint.tests ;
225 M: class-see-layout class-see-layout ;
229 "IN: prettyprint.tests"
230 "TUPLE: class-see-layout ;"
232 "IN: prettyprint.tests"
233 "GENERIC: class-see-layout ( x -- y )"
237 [ \ class-see-layout see ] with-string-writer "\n" split
242 "USING: prettyprint.tests ;"
243 "M: class-see-layout class-see-layout ;"
247 [ \ class-see-layout see-methods ] with-string-writer "\n" split
250 [ ] [ \ in>> synopsis drop ] unit-test
254 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
256 "generic-decl-test" "prettyprint.tests" lookup
257 [ see ] with-string-writer =
261 [ \ + (step-into-execute) ] (remove-breakpoints)
264 [ [ (step-into-execute) ] ] [
265 [ (step-into-execute) ] (remove-breakpoints)
269 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
273 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
276 GENERIC: generic-see-test-with-f ( obj -- obj )
278 M: f generic-see-test-with-f ;
280 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
281 [ M\ f generic-see-test-with-f see ] with-string-writer
284 PREDICATE: predicate-see-test < integer even? ;
286 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
287 [ \ predicate-see-test see ] with-string-writer
290 INTERSECTION: intersection-see-test sequence number ;
292 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
293 [ \ intersection-see-test see ] with-string-writer
296 [ ] [ \ compose see ] unit-test
297 [ ] [ \ curry see ] unit-test
299 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
301 TUPLE: started-out-hustlin' ;
303 GENERIC: ended-up-ballin' ( a -- b )
305 M: started-out-hustlin' ended-up-ballin' ; inline
307 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
308 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer