]> gitweb.factorcode.org Git - factor.git/blob - extra/multi-methods/tests/canonicalize.factor
maintain gml, euler, flatland, pong, multi-methods, pair-rockets, variables.
[factor.git] / extra / multi-methods / tests / canonicalize.factor
1 USING: multi-methods tools.test math sequences namespaces system
2 kernel strings ;
3 IN: multi-methods.tests
4
5 [ { POSTPONE: f integer } ] [ { f integer } canonicalize-specializer-0 ] unit-test
6
7 : setup-canon-test ( -- )
8     0 args set
9     V{ } clone hooks set ;
10
11 : canon-test-1 ( -- seq )
12     { integer { cpu x86 } sequence } canonicalize-specializer-1 ;
13
14 [ { { -2 integer } { -1 sequence } { cpu x86 } } ] [
15     [
16         setup-canon-test
17         canon-test-1
18     ] with-scope
19 ] unit-test
20
21 [ { { 0 integer } { 1 sequence } { 2 x86 } } ] [
22     [
23         setup-canon-test
24         canon-test-1
25         canonicalize-specializer-2
26     ] with-scope
27 ] unit-test
28
29 [ { integer sequence x86 } ] [
30     [
31         setup-canon-test
32         canon-test-1
33         canonicalize-specializer-2
34         args get hooks get length + total set
35         canonicalize-specializer-3
36     ] with-scope
37 ] unit-test
38
39 CONSTANT: example-1
40     {
41         { { { cpu x86 } { os linux } } "a" }
42         { { { cpu ppc } } "b" }
43         { { string { os windows } } "c" }
44     }
45
46 [
47     {
48         { { object x86 linux } "a"  }
49         { { object ppc object } "b" }
50         { { string object windows } "c" }
51     }
52     { cpu os }
53 ] [
54     example-1 canonicalize-specializers
55 ] unit-test
56
57 [
58     {
59         { { object x86 linux } [ drop drop "a" ] }
60         { { object ppc object } [ drop drop "b" ] }
61         { { string object windows } [ drop drop "c" ] }
62     }
63     [ \ cpu get \ os get ]
64 ] [
65     example-1 prepare-methods
66 ] unit-test