remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / core / destructors / destructors-tests.factor
blobe09a88aee4ba7acef0643b612f5fd1b45158597e
1 USING: destructors kernel tools.test continuations accessors
2 namespaces sequences ;
3 IN: destructors.tests
5 TUPLE: dispose-error ;
7 M: dispose-error dispose 3 throw ;
9 TUPLE: dispose-dummy disposed? ;
11 M: dispose-dummy dispose t >>disposed? drop ;
13 T{ dispose-error } "a" set
14 T{ dispose-dummy } "b" set
16 [ f ] [ "b" get disposed?>> ] unit-test
18 [ { "a" "b" } [ get ] map dispose-each ] [ 3 = ] must-fail-with
20 [ t ] [ "b" get disposed?>> ] unit-test
22 TUPLE: dummy-obj destroyed? ;
24 : <dummy-obj> dummy-obj new ;
26 TUPLE: dummy-destructor obj ;
28 C: <dummy-destructor> dummy-destructor
30 M: dummy-destructor dispose ( obj -- )
31     obj>> t >>destroyed? drop ;
33 : destroy-always
34     <dummy-destructor> &dispose drop ;
36 : destroy-later
37     <dummy-destructor> |dispose drop ;
39 [ t ] [
40     [
41         <dummy-obj> dup destroy-always
42     ] with-destructors destroyed?>>
43 ] unit-test
45 [ f ] [
46     [
47         <dummy-obj> dup destroy-later
48     ] with-destructors destroyed?>>
49 ] unit-test
51 [ t ] [
52     <dummy-obj> [
53         [
54             dup destroy-always
55             "foo" throw
56         ] with-destructors
57     ] ignore-errors destroyed?>>
58 ] unit-test
60 [ t ] [
61     <dummy-obj> [
62         [
63             dup destroy-later
64             "foo" throw
65         ] with-destructors
66     ] ignore-errors destroyed?>>
67 ] unit-test