]> gitweb.factorcode.org Git - factor.git/blob - extra/pair-methods/pair-methods-tests.factor
0d1d25d4a9bdd8effa09ebec927c9647c4f31f6e
[factor.git] / extra / pair-methods / pair-methods-tests.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors pair-methods classes kernel sequences tools.test ;
3 IN: pair-methods.tests
4
5 TUPLE: thang ;
6
7 TUPLE: foom < thang ;
8 TUPLE: barm < foom ;
9
10 TUPLE: zim < thang ;
11 TUPLE: zang < zim ;
12
13 : class-names ( a b prefix -- string )
14     [ [ class-of name>> ] bi@ "-" glue ] dip prepend ;
15
16 PAIR-GENERIC: blibble ( a b -- c )
17
18 PAIR-M: thang thang blibble
19     "vanilla " class-names ;
20
21 PAIR-M: foom thang blibble
22     "chocolate " class-names ;
23
24 PAIR-M: barm thang blibble
25     "strawberry " class-names ;
26
27 PAIR-M: barm zim blibble
28     "coconut " class-names ;
29
30 { "vanilla zang-zim" } [ zim new zang new blibble ] unit-test
31
32 ! args automatically swap to match most specific method
33 { "chocolate foom-zim" } [ foom new zim  new blibble ] unit-test
34 { "chocolate foom-zim" } [ zim  new foom new blibble ] unit-test
35
36 { "strawberry barm-barm" } [ barm new barm new blibble ] unit-test
37 { "strawberry barm-foom" } [ barm new foom new blibble ] unit-test
38 { "strawberry barm-foom" } [ foom new barm new blibble ] unit-test
39
40 { "coconut barm-zang" } [ zang new barm new blibble ] unit-test
41 { "coconut barm-zim" } [ barm new zim  new blibble ] unit-test
42
43 [ 1 2 blibble ] [ no-pair-method? ] must-fail-with