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 -- ? )
97 [ parse-fresh drop ] with-compilation-unit
99 "prettyprint.tests" lookup see
100 ] with-string-writer "\n" split but-last
104 GENERIC: method-layout ( a -- b )
106 M: complex method-layout
108 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
111 M: fixnum method-layout ;
113 M: integer method-layout ;
115 M: object method-layout ;
119 "USING: kernel math prettyprint.tests ;"
120 "M: complex method-layout"
122 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
125 "USING: math prettyprint.tests ;"
126 "M: fixnum method-layout ;"
128 "USING: math prettyprint.tests ;"
129 "M: integer method-layout ;"
131 "USING: kernel prettyprint.tests ;"
132 "M: object method-layout ;"
136 [ \ method-layout see-methods ] with-string-writer "\n" split
139 : soft-break-test ( -- str )
141 "USING: kernel math sequences strings ;"
142 "IN: prettyprint.tests"
143 ": soft-break-layout ( x y -- ? )"
145 " over hashcode over hashcode number="
146 " [ sequence= ] [ 2drop f ] if"
147 " ] [ 2drop f ] if ;"
151 "soft-break-layout" soft-break-test check-see
154 DEFER: parse-error-file
156 : another-soft-break-test ( -- str )
158 "USING: make sequences ;"
159 "IN: prettyprint.tests"
160 ": another-soft-break-layout ( node -- quot )"
162 " [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
166 "another-soft-break-layout" another-soft-break-test
170 : string-layout ( -- str )
172 "USING: accessors debugger io kernel ;"
173 "IN: prettyprint.tests"
174 ": string-layout-test ( error -- )"
175 " \"Expected \" write dup want>> expected>string write"
176 " \" but got \" write got>> expected>string print ;"
181 "string-layout-test" string-layout check-see
184 : narrow-test ( -- array )
186 "USING: arrays combinators continuations kernel sequences ;"
187 "IN: prettyprint.tests"
188 ": narrow-layout ( obj1 obj2 -- obj3 )"
190 " { [ dup continuation? ] [ append ] }"
191 " { [ dup not ] [ drop reverse ] }"
192 " { [ dup pair? ] [ [ delete ] keep ] }"
197 "narrow-layout" narrow-test check-see
200 : another-narrow-test ( -- array )
202 "IN: prettyprint.tests"
203 ": another-narrow-layout ( -- obj )"
216 "another-narrow-layout" another-narrow-test check-see
219 IN: prettyprint.tests
220 TUPLE: class-see-layout ;
222 IN: prettyprint.tests
223 GENERIC: class-see-layout ( x -- y )
225 USING: prettyprint.tests ;
226 M: class-see-layout class-see-layout ;
230 "IN: prettyprint.tests"
231 "TUPLE: class-see-layout ;"
233 "IN: prettyprint.tests"
234 "GENERIC: class-see-layout ( x -- y )"
238 [ \ class-see-layout see ] with-string-writer "\n" split
243 "USING: prettyprint.tests ;"
244 "M: class-see-layout class-see-layout ;"
248 [ \ class-see-layout see-methods ] with-string-writer "\n" split
251 [ ] [ \ in>> synopsis drop ] unit-test
255 "IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
257 "generic-decl-test" "prettyprint.tests" lookup
258 [ see ] with-string-writer =
261 [ [ + ] ] [ [ \ + (step-into-execute) ] (remove-breakpoints) ] unit-test
263 [ [ (step-into-execute) ] ] [ [ (step-into-execute) ] (remove-breakpoints) ] unit-test
266 [ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
270 [ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
273 GENERIC: generic-see-test-with-f ( obj -- obj )
275 M: f generic-see-test-with-f ;
277 [ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
278 [ M\ f generic-see-test-with-f see ] with-string-writer
281 PREDICATE: predicate-see-test < integer even? ;
283 [ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
284 [ \ predicate-see-test see ] with-string-writer
287 INTERSECTION: intersection-see-test sequence number ;
289 [ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
290 [ \ intersection-see-test see ] with-string-writer
293 [ ] [ \ compose see ] unit-test
294 [ ] [ \ curry see ] unit-test
296 [ "POSTPONE: [" ] [ \ [ unparse ] unit-test
298 TUPLE: started-out-hustlin' ;
300 GENERIC: ended-up-ballin' ( a -- b )
302 M: started-out-hustlin' ended-up-ballin' ; inline
304 [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
305 [ M\ started-out-hustlin' ended-up-ballin' see ] with-string-writer