]> gitweb.factorcode.org Git - factor.git/blob - basis/regexp/combinators/combinators-tests.factor
Switch to https urls
[factor.git] / basis / regexp / combinators / combinators-tests.factor
1 ! Copyright (C) 2009 Daniel Ehrenberg
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: regexp.combinators tools.test regexp kernel sequences ;
4 IN: regexp.combinators.tests
5
6 : strings ( -- regexp )
7     { "foo" "bar" "baz" } <any-of> ;
8
9 { t t t } [ "foo" "bar" "baz" [ strings matches? ] tri@ ] unit-test
10 { f f f } [ "food" "ibar" "ba" [ strings matches? ] tri@ ] unit-test
11
12 : conj ( -- regexp )
13     { R/ .*a/ R/ b.*/ } <and> ;
14
15 { t } [ "bljhasflsda" conj matches? ] unit-test
16 { f } [ "bsdfdfs" conj matches? ] unit-test
17 { f } [ "fsfa" conj matches? ] unit-test
18
19 { f } [ "bljhasflsda" conj <not> matches? ] unit-test
20 { t } [ "bsdfdfs" conj <not> matches? ] unit-test
21 { t } [ "fsfa" conj <not> matches? ] unit-test
22
23 { f f } [ "" "hi" [ <nothing> matches? ] bi@ ] unit-test
24 { t t } [ "" "hi" [ <nothing> <not> matches? ] bi@ ] unit-test
25
26 { { t t t f } } [ { "" "a" "aaaaa" "aab" } [ "a" <literal> <zero-or-more> matches? ] map ] unit-test
27 { { f t t f } } [ { "" "a" "aaaaa" "aab" } [ "a" <literal> <one-or-more> matches? ] map ] unit-test
28 { { t t f f } } [ { "" "a" "aaaaa" "aab" } [ "a" <literal> <option> matches? ] map ] unit-test