factor/basis/match/match-tests.factor

105 lines
1.6 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2006 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel match namespaces tools.test ;
2008-03-01 17:00:45 -05:00
IN: match.tests
2007-09-20 18:09:08 -04:00
MATCH-VARS: ?a ?b ;
{ f } [ { ?a ?a } { 1 2 } match ] unit-test
2007-10-28 00:28:46 -04:00
{ H{ { ?a 1 } { ?b 2 } } } [
2013-07-24 17:52:09 -04:00
{ ?a ?b } { 1 2 } match
2007-09-20 18:09:08 -04:00
] unit-test
{ { 1 2 } } [
2013-07-24 17:52:09 -04:00
{ 1 2 }
{
{ { ?a ?b } [ ?a ?b 2array ] }
} match-cond
2007-09-20 18:09:08 -04:00
] unit-test
{ t } [
2013-07-24 17:52:09 -04:00
{ 1 2 }
{
{ { 1 2 } [ t ] }
{ f [ f ] }
} match-cond
2007-09-20 18:09:08 -04:00
] unit-test
{ t } [
2013-07-24 17:52:09 -04:00
{ 1 3 }
{
{ { 1 2 } [ t ] }
{ { 1 3 } [ t ] }
} match-cond
2007-09-20 18:09:08 -04:00
] unit-test
{ f } [
2013-07-24 17:52:09 -04:00
{ 1 5 }
{
{ { 1 2 } [ t ] }
{ { 1 3 } [ t ] }
{ _ [ f ] }
} match-cond
2007-09-20 18:09:08 -04:00
] unit-test
TUPLE: foo a b ;
C: <foo> foo
{ 1 2 } [
2013-07-24 17:52:09 -04:00
1 2 <foo> T{ foo f ?a ?b } match [
?a ?b
] with-variables
2007-09-20 18:09:08 -04:00
] unit-test
{ 1 2 } [
2013-07-24 17:52:09 -04:00
1 2 <foo> \ ?a \ ?b <foo> match [
?a ?b
] with-variables
2007-09-20 18:09:08 -04:00
] unit-test
2013-07-25 10:02:47 -04:00
{ H{ { ?a ?a } } } [
2013-07-24 17:52:09 -04:00
\ ?a \ ?a match
2007-09-20 18:09:08 -04:00
] unit-test
{ "match" } [
2013-07-24 17:52:09 -04:00
"abcd" {
{ ?a [ "match" ] }
} match-cond
2007-09-20 18:09:08 -04:00
] unit-test
{ "one" } [
1 {
{ 1 [ "one" ] }
} match-cond
] unit-test
[
2 {
{ 1 [ "one" ] }
} match-cond
] [ no-match-cond? ] must-fail-with
{ "default" } [
2 {
{ 1 [ "one" ] }
[ drop "default" ]
} match-cond
] unit-test
2013-07-24 17:52:09 -04:00
{ { 2 1 } } [
{ "a" 1 2 "b" } { _ ?a ?b _ } { ?b ?a } match-replace
2007-09-20 18:09:08 -04:00
] unit-test
TUPLE: match-replace-test a b ;
{
2007-09-20 18:09:08 -04:00
T{ match-replace-test f 2 1 }
} [
2013-07-24 17:52:09 -04:00
T{ match-replace-test f 1 2 }
T{ match-replace-test f ?a ?b }
T{ match-replace-test f ?b ?a }
match-replace
2007-09-20 18:09:08 -04:00
] unit-test