]> gitweb.factorcode.org Git - factor.git/blob - core/generic/hook/hook-tests.factor
factor: Retrying on the unit tests. Also normalize some syntax with FUNCTION:.
[factor.git] / core / generic / hook / hook-tests.factor
1 USING: arrays generic generic.single growable kernel math
2 namespaces sequences strings tools.test vectors words ;
3 IN: generic.hook.tests
4
5 SYMBOL: my-var
6 HOOK: my-hook my-var ( -- x )
7
8 M: integer my-hook "an integer" ;
9 M: string my-hook "a string" ;
10
11 { "an integer" } [ 3 my-var set my-hook ] unit-test
12 { "a string" } [ my-hook my-var set my-hook ] unit-test
13 [ 1.0 my-var set my-hook ] [ T{ no-method f 1.0 my-hook } = ] must-fail-with
14
15 HOOK: call-next-hooker my-var ( -- x )
16
17 M: sequence call-next-hooker "sequence" ;
18
19 M: array call-next-hooker call-next-method "array " prepend ;
20
21 M: vector call-next-hooker call-next-method "vector " prepend ;
22
23 M: growable call-next-hooker call-next-method "growable " prepend ;
24
25 { "vector growable sequence" } [
26     V{ } my-var [ call-next-hooker ] with-variable
27 ] unit-test
28
29 { t } [
30     { } \ nth effective-method nip M\ sequence nth eq?
31 ] unit-test
32
33 { t } [
34     \ + \ nth effective-method nip dup \ nth "default-method" word-prop eq? and
35 ] unit-test