factor/basis/prettyprint/prettyprint-tests.factor

368 lines
8.7 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: arrays definitions io.streams.string io.streams.duplex
kernel math namespaces parser prettyprint prettyprint.config
prettyprint.sections sequences tools.test vectors words
2007-10-05 17:54:02 -04:00
effects splitting generic.standard prettyprint.private
2008-08-29 11:27:31 -04:00
continuations generic compiler.units tools.walker eval
accessors make ;
2008-03-01 17:00:45 -05:00
IN: prettyprint.tests
2007-09-20 18:09:08 -04:00
[ "4" ] [ 4 unparse ] unit-test
[ "1.0" ] [ 1.0 unparse ] unit-test
[ "1267650600228229401496703205376" ] [ 1 100 shift unparse ] unit-test
[ "+" ] [ \ + unparse ] unit-test
[ "\\ +" ] [ [ \ + ] first unparse ] unit-test
[ "{ }" ] [ { } unparse ] unit-test
[ "{ 1 2 3 }" ] [ { 1 2 3 } unparse ] unit-test
[ "\"hello\\\\backslash\"" ]
[ "hello\\backslash" unparse ]
unit-test
2008-02-02 16:00:05 -05:00
! [ "\"\\u123456\"" ]
! [ "\u123456" unparse ]
! unit-test
2007-09-20 18:09:08 -04:00
[ "\"\\e\"" ]
[ "\e" unparse ]
unit-test
[ "f" ] [ f unparse ] unit-test
[ "t" ] [ t unparse ] unit-test
[ "SBUF\" hello world\"" ] [ SBUF" hello world" unparse ] unit-test
[ "W{ \\ + }" ] [ [ W{ \ + } ] first unparse ] unit-test
[ ] [ \ fixnum see ] unit-test
[ ] [ \ integer see ] unit-test
2008-01-02 19:36:36 -05:00
[ ] [ \ generic see ] unit-test
2007-09-20 18:09:08 -04:00
[ ] [ \ duplex-stream see ] unit-test
[ "[ \\ + ]" ] [ [ \ + ] unparse ] unit-test
[ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
[ t ] [
2008-02-21 02:26:44 -05:00
100 \ dup <array> unparse-short
2007-09-20 18:09:08 -04:00
"{" head?
] unit-test
: foo ( a -- b ) dup * ; inline
2008-03-01 17:00:45 -05:00
[ "USING: kernel math ;\nIN: prettyprint.tests\n: foo ( a -- b ) dup * ; inline\n" ]
[ [ \ foo see ] with-string-writer ] unit-test
2007-09-20 18:09:08 -04:00
: bar ( x -- y ) 2 + ;
2008-03-01 17:00:45 -05:00
[ "USING: math ;\nIN: prettyprint.tests\n: bar ( x -- y ) 2 + ;\n" ]
[ [ \ bar see ] with-string-writer ] unit-test
2007-09-20 18:09:08 -04:00
: blah
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop
drop ;
[ "drop ;" ] [
\ blah f "inferred-effect" set-word-prop
[ \ blah see ] with-string-writer "\n" ?tail drop 6 tail*
2007-09-20 18:09:08 -04:00
] unit-test
: check-see ( expect name -- )
[
use [ clone ] change
[
2007-12-24 19:40:09 -05:00
[ parse-fresh drop ] with-compilation-unit
[
2008-03-01 17:00:45 -05:00
"prettyprint.tests" lookup see
2008-05-07 02:38:34 -04:00
] with-string-writer "\n" split but-last
2007-09-20 18:09:08 -04:00
] keep =
] with-scope ;
2008-06-29 22:37:57 -04:00
GENERIC: method-layout
M: complex method-layout
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
;
M: fixnum method-layout ;
M: integer method-layout ;
M: object method-layout ;
[
2007-09-20 18:09:08 -04:00
{
2008-03-03 17:44:24 -05:00
"USING: math prettyprint.tests ;"
2007-09-20 18:09:08 -04:00
"M: complex method-layout"
" \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
" ;"
""
2008-03-03 17:44:24 -05:00
"USING: math prettyprint.tests ;"
2007-09-20 18:09:08 -04:00
"M: fixnum method-layout ;"
""
2008-03-03 17:44:24 -05:00
"USING: math prettyprint.tests ;"
2007-09-20 18:09:08 -04:00
"M: integer method-layout ;"
""
2008-03-03 17:44:24 -05:00
"USING: kernel prettyprint.tests ;"
2007-09-20 18:09:08 -04:00
"M: object method-layout ;"
2008-06-29 22:37:57 -04:00
""
}
] [
[ \ method-layout see-methods ] with-string-writer "\n" split
2007-09-20 18:09:08 -04:00
] unit-test
: retain-stack-test
{
"USING: io kernel sequences words ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
": retain-stack-layout ( x -- )"
2007-09-20 18:09:08 -04:00
" dup stream-readln stream-readln"
2008-01-02 19:36:36 -05:00
" >r [ define ] map r>"
" define ;"
2007-09-20 18:09:08 -04:00
} ;
[ t ] [
"retain-stack-layout" retain-stack-test check-see
] unit-test
: soft-break-test
{
"USING: kernel math sequences strings ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
": soft-break-layout ( x y -- ? )"
2007-09-20 18:09:08 -04:00
" over string? ["
" over hashcode over hashcode number="
" [ sequence= ] [ 2drop f ] if"
" ] [ 2drop f ] if ;"
} ;
[ t ] [
"soft-break-layout" soft-break-test check-see
] unit-test
: another-retain-layout-test
{
"USING: kernel sequences ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2007-09-20 18:09:08 -04:00
": another-retain-layout ( seq1 seq2 quot -- newseq )"
" -rot 2dup dupd min-length [ each drop roll ] map"
" >r 3drop r> ; inline"
} ;
[ t ] [
"another-retain-layout" another-retain-layout-test check-see
] unit-test
2008-06-25 05:06:18 -04:00
DEFER: parse-error-file
2007-09-20 18:09:08 -04:00
: another-soft-break-test
{
"USING: make sequences ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2007-09-20 18:09:08 -04:00
": another-soft-break-layout ( node -- quot )"
" parse-error-file"
2008-03-31 21:24:48 -04:00
" [ <reversed> \"hello world foo\" suffix ] [ ] make ;"
2007-09-20 18:09:08 -04:00
} ;
[ t ] [
"another-soft-break-layout" another-soft-break-test
check-see
] unit-test
: string-layout
{
2008-08-30 22:55:29 -04:00
"USING: accessors debugger io kernel ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
": string-layout-test ( error -- )"
2008-08-30 22:55:29 -04:00
" \"Expected \" write dup want>> expected>string write"
" \" but got \" write got>> expected>string print ;"
2007-09-20 18:09:08 -04:00
} ;
[ t ] [
"string-layout-test" string-layout check-see
] unit-test
! Define dummy words for the below...
: <NSRect> ( a b c d -- e ) ;
: <PixelFormat> ( -- fmt ) ;
: send ( obj -- ) ;
\ send soft "break-after" set-word-prop
: final-soft-break-test
{
"USING: kernel sequences ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2007-09-20 18:09:08 -04:00
": final-soft-break-layout ( class dim -- view )"
" >r \"alloc\" send 0 0 r>"
" first2 <NSRect>"
" <PixelFormat> \"initWithFrame:pixelFormat:\" send"
" dup 1 \"setPostsBoundsChangedNotifications:\" send"
" dup 1 \"setPostsFrameChangedNotifications:\" send ;"
} ;
[ t ] [
"final-soft-break-layout" final-soft-break-test check-see
] unit-test
: narrow-test
{
"USING: arrays combinators continuations kernel sequences ;"
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2007-09-20 18:09:08 -04:00
": narrow-layout ( obj -- )"
" {"
" { [ dup continuation? ] [ append ] }"
" { [ dup not ] [ drop reverse ] }"
" { [ dup pair? ] [ delete ] }"
" } cond ;"
} ;
[ t ] [
"narrow-layout" narrow-test check-see
] unit-test
: another-narrow-test
{
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
": another-narrow-layout ( -- obj )"
2007-09-20 18:09:08 -04:00
" H{"
" { 1 2 }"
" { 3 4 }"
" { 5 6 }"
" { 7 8 }"
" { 9 10 }"
" { 11 12 }"
" { 13 14 }"
" } ;"
} ;
[ t ] [
"another-narrow-layout" another-narrow-test check-see
] unit-test
2008-06-29 22:37:57 -04:00
IN: prettyprint.tests
TUPLE: class-see-layout ;
IN: prettyprint.tests
GENERIC: class-see-layout ( x -- y )
USING: prettyprint.tests ;
M: class-see-layout class-see-layout ;
[
2007-12-25 18:11:56 -05:00
{
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
"TUPLE: class-see-layout ;"
""
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests"
2008-01-04 21:10:49 -05:00
"GENERIC: class-see-layout ( x -- y )"
2007-12-25 18:11:56 -05:00
""
2008-06-29 22:37:57 -04:00
}
] [
[ \ class-see-layout see ] with-string-writer "\n" split
] unit-test
[
{
2008-03-03 17:44:24 -05:00
"USING: prettyprint.tests ;"
2007-12-25 18:11:56 -05:00
"M: class-see-layout class-see-layout ;"
2008-06-29 22:37:57 -04:00
""
}
] [
[ \ class-see-layout see-methods ] with-string-writer "\n" split
2007-12-25 18:11:56 -05:00
] unit-test
2008-08-29 11:27:31 -04:00
[ ] [ \ in>> synopsis drop ] unit-test
2007-10-05 15:26:40 -04:00
! Regression
[ t ] [
2008-03-01 17:00:45 -05:00
"IN: prettyprint.tests\nGENERIC: generic-decl-test ( a -- b ) flushable\n"
dup eval
2008-03-01 17:00:45 -05:00
"generic-decl-test" "prettyprint.tests" lookup
[ see ] with-string-writer =
] unit-test
2007-10-05 15:26:40 -04:00
[ [ + ] ] [
2008-02-21 03:08:08 -05:00
[ \ + (step-into-execute) ] (remove-breakpoints)
2007-10-05 15:26:40 -04:00
] unit-test
2008-02-21 03:08:08 -05:00
[ [ (step-into-execute) ] ] [
[ (step-into-execute) ] (remove-breakpoints)
2007-10-05 15:26:40 -04:00
] unit-test
[ [ 2 2 + . ] ] [
2008-02-21 03:08:08 -05:00
[ 2 2 \ + (step-into-execute) . ] (remove-breakpoints)
2007-10-05 15:26:40 -04:00
] unit-test
[ [ 2 2 + . ] ] [
2008-02-21 03:08:08 -05:00
[ 2 break 2 \ + (step-into-execute) . ] (remove-breakpoints)
2007-10-09 01:30:28 -04:00
] unit-test
[ ] [ 1 \ + curry unparse drop ] unit-test
[ ] [ 1 \ + compose unparse drop ] unit-test
2008-03-18 22:43:29 -04:00
GENERIC: generic-see-test-with-f ( obj -- obj )
M: f generic-see-test-with-f ;
[ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
[ { POSTPONE: f generic-see-test-with-f } see ] with-string-writer
] unit-test
[ "USING: prettyprint.tests ;\nM: f generic-see-test-with-f ;\n" ] [
[ \ f \ generic-see-test-with-f method see ] with-string-writer
] unit-test
2008-03-26 19:23:19 -04:00
PREDICATE: predicate-see-test < integer even? ;
[ "USING: math ;\nIN: prettyprint.tests\nPREDICATE: predicate-see-test < integer even? ;\n" ] [
[ \ predicate-see-test see ] with-string-writer
] unit-test
2008-04-03 20:08:34 -04:00
2008-05-11 01:41:47 -04:00
INTERSECTION: intersection-see-test sequence number ;
[ "USING: math sequences ;\nIN: prettyprint.tests\nINTERSECTION: intersection-see-test sequence number ;\n" ] [
[ \ intersection-see-test see ] with-string-writer
] unit-test
2008-04-03 20:08:34 -04:00
[ ] [ \ compose see ] unit-test
[ ] [ \ curry see ] unit-test
[ "POSTPONE: [" ] [ \ [ unparse ] unit-test
TUPLE: started-out-hustlin' ;
GENERIC: ended-up-ballin'
M: started-out-hustlin' ended-up-ballin' ; inline
[ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [
[ { started-out-hustlin' ended-up-ballin' } see ] with-string-writer
] unit-test