]> gitweb.factorcode.org Git - factor.git/blob - basis/match/match-tests.factor
Revert "interpolate: allow format directives to be used"
[factor.git] / basis / match / match-tests.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays kernel match namespaces tools.test ;
4 FROM: match => _ ;
5 IN: match.tests
6
7 MATCH-VARS: ?a ?b ;
8
9 { f } [ { ?a ?a } { 1 2 } match ] unit-test
10
11 { H{ { ?a 1 } { ?b 2 } } } [
12     { ?a ?b } { 1 2 } match
13 ] unit-test
14
15 { { 1 2 } } [
16     { 1 2 }
17     {
18         { { ?a ?b } [ ?a ?b 2array ] }
19     } match-cond
20 ] unit-test
21
22 { t } [
23     { 1 2 }
24     {
25         { { 1 2 } [ t ] }
26         { f [ f ] }
27     } match-cond
28 ] unit-test
29
30 { t } [
31     { 1 3 }
32     {
33         { { 1 2 } [ t ] }
34         { { 1 3 } [ t ] }
35     } match-cond
36 ] unit-test
37
38 { f } [
39     { 1 5 }
40     {
41         { { 1 2 } [ t ] }
42         { { 1 3 } [ t ] }
43         { _       [ f ] }
44     } match-cond
45 ] unit-test
46
47 TUPLE: foo a b ;
48
49 C: <foo> foo
50
51 { 1 2 } [
52     1 2 <foo> T{ foo f ?a ?b } match [
53         ?a ?b
54     ] with-variables
55 ] unit-test
56
57 { 1 2 } [
58     1 2 <foo> \ ?a \ ?b <foo> match [
59         ?a ?b
60     ] with-variables
61 ] unit-test
62
63 { H{ { ?a ?a } } } [
64     \ ?a \ ?a match
65 ] unit-test
66
67 { "match" } [
68     "abcd" {
69         { ?a [ "match" ] }
70     } match-cond
71 ] unit-test
72
73 { "one" } [
74     1 {
75         { 1 [ "one" ] }
76     } match-cond
77 ] unit-test
78
79 [
80     2 {
81         { 1 [ "one" ] }
82     } match-cond
83 ] [ no-match-cond? ] must-fail-with
84
85 { "default" } [
86     2 {
87         { 1 [ "one" ] }
88         [ drop "default" ]
89     } match-cond
90 ] unit-test
91
92 { { 2 1 } } [
93     { "a" 1 2 "b" } { _ ?a ?b _ } { ?b ?a } match-replace
94 ] unit-test
95
96 TUPLE: match-replace-test a b ;
97
98 {
99     T{ match-replace-test f 2 1 }
100 } [
101     T{ match-replace-test f 1 2 }
102     T{ match-replace-test f ?a ?b }
103     T{ match-replace-test f ?b ?a }
104     match-replace
105 ] unit-test