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.continuations
6 tools.continuations.private eval 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
109 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
112 M: fixnum method-layout ;
114 M: integer method-layout ;
116 M: object method-layout ;
120 "USING: kernel math prettyprint.tests ;"
121 "M: complex method-layout"
123 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
126 "USING: math prettyprint.tests ;"
127 "M: fixnum method-layout ;"
129 "USING: math prettyprint.tests ;"
130 "M: integer method-layout ;"
132 "USING: kernel prettyprint.tests ;"
133 "M: object method-layout ;"
137 [ \ method-layout see-methods ] with-string-writer "\n" split
140 : soft-break-test ( -- str )
142 "USING: kernel math sequences strings ;"
143 "IN: prettyprint.tests"
144 ": soft-break-layout ( x y -- ? )"
146 " over hashcode over hashcode number="
147 " [ sequence= ] [ 2drop f ] if"
148 " ] [ 2drop f ] if ;"
152 "soft-break-layout" soft-break-test check-see
155 DEFER: parse-error-file
157 : another-soft-break-test ( -- str )
159 "USING: make sequences ;"
160 "IN: prettyprint.tests"
161 ": another-soft-break-layout ( node -- quot )"
163 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
167 "another-soft-break-layout" another-soft-break-test
171 : string-layout ( -- str )
173 "USING: accessors debugger io kernel ;"
174 "IN: prettyprint.tests"
175 ": string-layout-test ( error -- )"
176 " \"Expected \" write dup want>> expected>string write"
177 " \" but got \" write got>> expected>string print ;"
182 "string-layout-test" string-layout check-see
185 : narrow-test ( -- array )
187 "USING: arrays combinators continuations kernel sequences ;"
188 "IN: prettyprint.tests"
189 ": narrow-layout ( obj1 obj2 -- obj3 )"
191 " { [ dup continuation? ] [ append ] }"
192 " { [ dup not ] [ drop reverse ] }"
193 " { [ dup pair? ] [ [ delete ] keep ] }"
198 "narrow-layout" narrow-test check-see
201 : another-narrow-test ( -- array )
203 "IN: prettyprint.tests"
204 ": another-narrow-layout ( -- obj )"
217 "another-narrow-layout" another-narrow-test check-see
220 IN: prettyprint.tests
221 TUPLE: class-see-layout ;
223 IN: prettyprint.tests
224 GENERIC: class-see-layout ( x -- y )
226 USING: prettyprint.tests ;
227 M: class-see-layout class-see-layout ;
231 "IN: prettyprint.tests"
232 "TUPLE: class-see-layout ;"
234 "IN: prettyprint.tests"
235 "GENERIC: class-see-layout ( x -- y )"
239 [ \ class-see-layout see ] with-string-writer "\n" split
244 "USING: prettyprint.tests ;"
245 "M: class-see-layout class-see-layout ;"
249 [ \ class-see-layout see-methods ] with-string-writer "\n" split
252 [ ] [ \ in>> synopsis drop ] unit-test
256 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
258 "generic-decl-test" "prettyprint.tests" lookup
259 [ see ] with-string-writer =
262 [ [ + ] ] [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
264 [ [ (step-into-execute) ] ] [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
267 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
271 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
274 GENERIC: generic-see-test-with-f ( obj -- obj )
276 M: f generic-see-test-with-f ;
278 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
279 [ M\ f generic-see-test-with-f see ] with-string-writer
282 PREDICATE: predicate-see-test < integer even? ;
284 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
285 [ \ predicate-see-test see ] with-string-writer
288 INTERSECTION: intersection-see-test sequence number ;
290 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
291 [ \ intersection-see-test see ] with-string-writer
294 [ ] [ \ compose see ] unit-test
295 [ ] [ \ curry see ] unit-test
297 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
299 TUPLE: started-out-hustlin' ;
301 GENERIC: ended-up-ballin' ( a -- b )
303 M: started-out-hustlin' ended-up-ballin' ; inline
305 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
306 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer