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 see ] with-string-writer "\n" ?tail drop 6 tail*
92 : check-see ( expect name -- ? )
95 [ parse-fresh drop ] with-compilation-unit
97 "prettyprint.tests" lookup see
98 ] with-string-writer "\n" split but-last
100 ] with-interactive-vocabs ;
102 GENERIC: method-layout ( a -- b )
104 M: complex method-layout
106 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
109 M: fixnum method-layout ;
111 M: integer method-layout ;
113 M: object method-layout ;
117 "USING: kernel math prettyprint.tests ;"
118 "M: complex method-layout"
120 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
123 "USING: math prettyprint.tests ;"
124 "M: fixnum method-layout ;"
126 "USING: math prettyprint.tests ;"
127 "M: integer method-layout ;"
129 "USING: kernel prettyprint.tests ;"
130 "M: object method-layout ;"
134 [ \ method-layout see-methods ] with-string-writer "\n" split
137 : soft-break-test ( -- str )
139 "USING: kernel math sequences strings ;"
140 "IN: prettyprint.tests"
141 ": soft-break-layout ( x y -- ? )"
143 " over hashcode over hashcode number="
144 " [ sequence= ] [ 2drop f ] if"
145 " ] [ 2drop f ] if ;"
149 "soft-break-layout" soft-break-test check-see
152 DEFER: parse-error-file
154 : another-soft-break-test ( -- str )
156 "USING: make sequences ;"
157 "IN: prettyprint.tests"
158 ": another-soft-break-layout ( node -- quot )"
160 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
164 "another-soft-break-layout" another-soft-break-test
168 : string-layout ( -- str )
170 "USING: accessors debugger io kernel ;"
171 "IN: prettyprint.tests"
172 ": string-layout-test ( error -- )"
173 " \"Expected \" write dup want>> expected>string write"
174 " \" but got \" write got>> expected>string print ;"
179 "string-layout-test" string-layout check-see
182 : narrow-test ( -- array )
184 "USING: arrays combinators continuations kernel sequences ;"
185 "IN: prettyprint.tests"
186 ": narrow-layout ( obj1 obj2 -- obj3 )"
188 " { [ dup continuation? ] [ append ] }"
189 " { [ dup not ] [ drop reverse ] }"
190 " { [ dup pair? ] [ [ delete ] keep ] }"
195 "narrow-layout" narrow-test check-see
198 : another-narrow-test ( -- array )
200 "IN: prettyprint.tests"
201 ": another-narrow-layout ( -- obj )"
214 "another-narrow-layout" another-narrow-test check-see
217 IN: prettyprint.tests
218 TUPLE: class-see-layout ;
220 IN: prettyprint.tests
221 GENERIC: class-see-layout ( x -- y )
223 USING: prettyprint.tests ;
224 M: class-see-layout class-see-layout ;
228 "IN: prettyprint.tests"
229 "TUPLE: class-see-layout ;"
231 "IN: prettyprint.tests"
232 "GENERIC: class-see-layout ( x -- y )"
236 [ \ class-see-layout see ] with-string-writer "\n" split
241 "USING: prettyprint.tests ;"
242 "M: class-see-layout class-see-layout ;"
246 [ \ class-see-layout see-methods ] with-string-writer "\n" split
249 [ ] [ \ in>> synopsis drop ] unit-test
253 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
255 "generic-decl-test" "prettyprint.tests" lookup
256 [ see ] with-string-writer =
259 [ [ + ] ] [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
261 [ [ (step-into-execute) ] ] [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
264 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
268 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
271 GENERIC: generic-see-test-with-f ( obj -- obj )
273 M: f generic-see-test-with-f ;
275 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
276 [ M\ f generic-see-test-with-f see ] with-string-writer
279 PREDICATE: predicate-see-test < integer even? ;
281 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
282 [ \ predicate-see-test see ] with-string-writer
285 INTERSECTION: intersection-see-test sequence number ;
287 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
288 [ \ intersection-see-test see ] with-string-writer
291 [ ] [ \ compose see ] unit-test
292 [ ] [ \ curry see ] unit-test
294 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
296 TUPLE: started-out-hustlin' ;
298 GENERIC: ended-up-ballin' ( a -- b )
300 M: started-out-hustlin' ended-up-ballin' ; inline
302 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
303 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer