factor/core/continuations/continuations-tests.factor

109 lines
2.4 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: kernel math namespaces io tools.test sequences vectors
continuations debugger parser memory arrays words
kernel.private accessors eval ;
2008-03-01 17:00:45 -05:00
IN: continuations.tests
2007-09-20 18:09:08 -04:00
2009-04-17 15:44:08 -04:00
: (callcc1-test) ( n obj -- n' obj )
[ 1 - dup ] dip ?push
2007-09-20 18:09:08 -04:00
over 0 = [ "test-cc" get continue-with ] when
(callcc1-test) ;
: callcc1-test ( x -- list )
[
"test-cc" set V{ } clone (callcc1-test)
] callcc1 nip ;
: callcc-namespace-test ( -- ? )
[
"test-cc" set
5 "x" set
[
6 "x" set "test-cc" get continue
] with-scope
] callcc0 "x" get 5 = ;
[ t ] [ 10 callcc1-test 10 reverse >vector = ] unit-test
[ t ] [ callcc-namespace-test ] unit-test
[ 5 throw ] [ 5 = ] must-fail-with
2007-09-20 18:09:08 -04:00
[ t ] [
[ "Hello" throw ] ignore-errors
error get-global
2007-09-20 18:09:08 -04:00
"Hello" =
] unit-test
"!!! The following error is part of the test" print
[ ] [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test
"!!! The following error is part of the test" print
2008-05-06 03:52:08 -04:00
[ ] [ [ [ "2 car" ] eval ] try ] unit-test
2007-09-20 18:09:08 -04:00
[ f throw ] must-fail
2007-09-20 18:09:08 -04:00
! Weird PowerPC bug.
[ ] [
[ "4" throw ] ignore-errors
gc
gc
2007-09-20 18:09:08 -04:00
] unit-test
! ! See how well callstack overflow is handled
! [ clear drop ] must-fail
2007-09-20 18:09:08 -04:00
!
! : callstack-overflow callstack-overflow f ;
! [ callstack-overflow ] must-fail
2009-04-22 08:05:00 -04:00
: don't-compile-me ( -- ) ;
: foo ( -- ) callstack "c" set don't-compile-me ;
2009-03-23 01:34:02 -04:00
: bar ( -- a b ) 1 foo 2 ;
2009-04-22 08:05:00 -04:00
<< { don't-compile-me foo bar } [ t "no-compile" set-word-prop ] each >>
[ 1 2 ] [ bar ] unit-test
[ t ] [ \ bar def>> "c" get innermost-frame-executing = ] unit-test
[ 1 ] [ "c" get innermost-frame-scan ] unit-test
SYMBOL: always-counter
SYMBOL: error-counter
[
0 always-counter set
0 error-counter set
[ ] [ always-counter inc ] [ error-counter inc ] cleanup
[ 1 ] [ always-counter get ] unit-test
[ 0 ] [ error-counter get ] unit-test
[
[ "a" throw ]
[ always-counter inc ]
[ error-counter inc ] cleanup
] [ "a" = ] must-fail-with
[ 2 ] [ always-counter get ] unit-test
[ 1 ] [ error-counter get ] unit-test
[
[ ]
[ always-counter inc "a" throw ]
[ error-counter inc ] cleanup
] [ "a" = ] must-fail-with
[ 3 ] [ always-counter get ] unit-test
[ 1 ] [ error-counter get ] unit-test
] with-scope
2008-05-01 22:42:51 -04:00
2008-05-07 08:49:29 -04:00
[ ] [ [ return ] with-return ] unit-test
2008-05-12 20:23:32 -04:00
[ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with
[ { 4 } ] [ { 2 2 } [ + ] with-datastack ] unit-test
[ with-datastack ] must-infer