]> gitweb.factorcode.org Git - factor.git/blob - basis/match/match-tests.factor
f24e5f7bf49d53b6c80b7b8106f013b56e22baf6
[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: tools.test match namespaces arrays ;
4 IN: match.tests
5
6 MATCH-VARS: ?a ?b ;
7
8 [ f ] [ { ?a ?a } { 1 2 } match ] unit-test
9
10 [ H{ { ?a 1 } { ?b 2 } } ] [
11     { ?a ?b } { 1 2 } match
12 ] unit-test
13
14 [ { 1 2 } ] [
15     { 1 2 }
16     {
17         { { ?a ?b } [ ?a ?b 2array ] }
18     } match-cond
19 ] unit-test
20
21 [ t ] [
22     { 1 2 }
23     {
24         { { 1 2 } [ t ] }
25         { f [ f ] }
26     } match-cond
27 ] unit-test
28
29 [ t ] [
30     { 1 3 }
31     {
32         { { 1 2 } [ t ] }
33         { { 1 3 } [ t ] }
34     } match-cond
35 ] unit-test
36
37 [ f ] [
38     { 1 5 }
39     {
40         { { 1 2 } [ t ] }
41         { { 1 3 } [ t ] }
42         { _       [ f ] }
43     } match-cond
44 ] unit-test
45
46 TUPLE: foo a b ;
47
48 C: <foo> foo
49
50 { 1 2 } [
51     1 2 <foo> T{ foo f ?a ?b } match [
52         ?a ?b
53     ] with-variables
54 ] unit-test
55
56 { 1 2 } [
57     1 2 <foo> \ ?a \ ?b <foo> match [
58         ?a ?b
59     ] with-variables
60 ] unit-test
61
62 { H{ { ?a ?a } } } [
63     \ ?a \ ?a match
64 ] unit-test
65
66 [ "match" ] [
67     "abcd" {
68         { ?a [ "match" ] }
69     } match-cond
70 ] unit-test
71
72 { { 2 1 } } [
73     { "a" 1 2 "b" } { _ ?a ?b _ } { ?b ?a } match-replace
74 ] unit-test
75
76 TUPLE: match-replace-test a b ;
77
78 [
79     T{ match-replace-test f 2 1 }
80 ] [
81     T{ match-replace-test f 1 2 }
82     T{ match-replace-test f ?a ?b }
83     T{ match-replace-test f ?b ?a }
84     match-replace
85 ] unit-test