factor/extra/delegate/delegate-tests.factor

51 lines
1.6 KiB
Factor
Raw Normal View History

2008-04-05 00:14:40 -04:00
USING: delegate kernel arrays tools.test words math definitions
compiler.units parser generic prettyprint io.streams.string ;
2008-03-01 17:00:45 -05:00
IN: delegate.tests
2008-04-03 20:17:58 -04:00
DEFER: example
[ 1 ] [ \ example 1 "prop" set-word-prop \ example "prop" word-prop ] unit-test
[ ] [ \ example "prop" [ 1+ ] change-word-prop ] unit-test
[ 2 ] [ \ example "prop" word-prop ] unit-test
TUPLE: hello this that ;
C: <hello> hello
TUPLE: goodbye these those ;
C: <goodbye> goodbye
GENERIC: foo ( x -- y )
GENERIC: bar ( a -- b )
2008-04-05 03:44:54 -04:00
GENERIC# whoa 1 ( s t -- w )
PROTOCOL: baz foo { bar 0 } { whoa 1 } ;
2008-04-05 00:14:40 -04:00
: hello-test ( hello/goodbye -- array )
[ hello? ] [ hello-this ] [ hello-that ] tri 3array ;
CONSULT: baz goodbye goodbye-these ;
M: hello foo hello-this ;
2008-04-05 00:14:40 -04:00
M: hello bar hello-test ;
2008-04-05 03:44:54 -04:00
M: hello whoa >r hello-this r> + ;
GENERIC: bing ( c -- d )
2008-04-05 03:44:54 -04:00
PROTOCOL: bee bing ;
2008-04-05 00:14:40 -04:00
CONSULT: hello goodbye goodbye-those ;
M: hello bing hello-test ;
2008-04-05 03:44:54 -04:00
MIMIC: bee goodbye hello
2008-04-05 00:14:40 -04:00
[ 1 { t 1 0 } ] [ 1 0 <hello> [ foo ] [ bar ] bi ] unit-test
[ { t 1 0 } ] [ 1 0 <hello> bing ] unit-test
[ 1 ] [ 1 0 <hello> f <goodbye> foo ] unit-test
2008-04-05 00:14:40 -04:00
[ { t 1 0 } ] [ 1 0 <hello> f <goodbye> bar ] unit-test
! [ { f 1 0 } ] [ f 1 0 <hello> <goodbye> bing ] unit-test
2008-04-05 03:44:54 -04:00
[ 3 ] [ 1 0 <hello> 2 whoa ] unit-test
[ 3 ] [ 1 0 <hello> f <goodbye> 2 whoa ] unit-test
2008-04-05 00:14:40 -04:00
[ ] [ 10 [ "USE: delegate IN: delegate.tests CONSULT: baz goodbye goodbye-these ;" eval ] times ] unit-test
[ V{ goodbye } ] [ baz protocol-users ] unit-test
! [ "USING: delegate ;\nIN: delegate.tests\nPROTOCOL: baz foo bar { whoa 1 } ;\n" ]
! [ [ baz see ] with-string-writer ] unit-test
2008-04-05 00:14:40 -04:00
! [ ] [ [ baz forget ] with-compilation-unit ] unit-test
! [ f ] [ goodbye baz method ] unit-test