1 USING: accessors continuations debugger eval hashtables io
2 kernel kernel.private math memory namespaces sequences
3 tools.test vectors words ;
4 IN: continuations.tests
6 : (callcc1-test) ( n obj -- n' obj )
8 over 0 = [ "test-cc" get continue-with ] when
11 : callcc1-test ( x -- list )
13 "test-cc" set V{ } clone (callcc1-test)
16 : callcc-namespace-test ( -- ? )
21 6 "x" set "test-cc" get continue
23 ] callcc0 "x" get 5 = ;
25 { t } [ 10 callcc1-test 10 iota reverse >vector = ] unit-test
26 { t } [ callcc-namespace-test ] unit-test
28 [ 5 throw ] [ 5 = ] must-fail-with
31 [ "Hello" throw ] ignore-errors
36 "!!! The following error is part of the test" print
38 { } [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test
40 "!!! The following error is part of the test" print
42 { } [ [ [ "2 car" ] eval ] try ] unit-test
48 [ "4" throw ] ignore-errors
53 : don't-compile-me ( -- ) ;
54 : foo ( -- ) get-callstack "c" set don't-compile-me ;
55 : bar ( -- a b ) 1 foo 2 ;
57 << { don't-compile-me foo bar } [ t "no-compile" set-word-prop ] each >>
59 { 1 2 } [ bar ] unit-test
61 { t } [ \ bar def>> "c" get innermost-frame-executing = ] unit-test
63 { 1 } [ "c" get innermost-frame-scan ] unit-test
65 SYMBOL: always-counter
69 0 error-counter 2hashtable
72 [ ] [ always-counter inc ] [ error-counter inc ] cleanup
74 [ 1 ] [ always-counter get ] unit-test
75 [ 0 ] [ error-counter get ] unit-test
79 [ always-counter inc ]
80 [ error-counter inc ] cleanup
81 ] [ "a" = ] must-fail-with
83 [ 2 ] [ always-counter get ] unit-test
84 [ 1 ] [ error-counter get ] unit-test
88 [ always-counter inc "a" throw ]
89 [ error-counter inc ] cleanup
90 ] [ "a" = ] must-fail-with
92 [ 3 ] [ always-counter get ] unit-test
93 [ 1 ] [ error-counter get ] unit-test
96 { } [ [ return ] with-return ] unit-test
98 [ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with
100 { { 4 } } [ { 2 2 } [ + ] with-datastack ] unit-test
102 [ with-datastack ] must-infer