]> gitweb.factorcode.org Git - factor.git/blob - extra/verbal-expressions/verbal-expressions-tests.factor
Reformat
[factor.git] / extra / verbal-expressions / verbal-expressions-tests.factor
1 USING: kernel regexp tools.test ;
2 IN: verbal-expressions
3
4 { f t } [
5     <verbexp> something >regexp
6     [ "" swap matches? ]
7     [ "a" swap matches? ] bi
8 ] unit-test
9
10 { t } [
11     "what" <verbexp> anything >regexp matches?
12 ] unit-test
13
14 { f t } [
15     <verbexp> start-of-line "w" anything-but >regexp
16     [ "what" swap matches? ]
17     [ "time" swap matches? ] bi
18 ] unit-test
19
20 { f t f } [
21     <verbexp> "a" something-but >regexp
22     [ "" swap matches? ]
23     [ "b" swap matches? ]
24     [ "a" swap matches? ] tri
25 ] unit-test
26
27 { t f } [
28     <verbexp> start-of-line "a" then >regexp
29     [ "a" swap matches? ]
30     [ "ba" swap matches? ] bi
31 ] unit-test
32
33 { t f } [
34     <verbexp> "a" then end-of-line >regexp
35     [ "a" swap matches? ]
36     [ "ab" swap matches? ] bi
37 ] unit-test
38
39 { t t } [
40     <verbexp> start-of-line "a" then "b" maybe >regexp
41     [ "acb" swap re-contains? ]
42     [ "abc" swap re-contains? ] bi
43 ] unit-test
44
45 { t f } [
46     <verbexp> start-of-line "a" then "xyz" any-of >regexp
47     [ "ay" swap matches? ]
48     [ "abc" swap matches? ] bi
49 ] unit-test
50
51 { t f } [
52     <verbexp> start-of-line "abc" then -or- "def" then >regexp
53     [ "defzz" swap re-contains? ]
54     [ "xyzabc" swap re-contains? ] bi
55 ] unit-test
56
57 { t t f } [
58     <verbexp> start-of-line "abc" then line-break "def" then >regexp
59     [ "abc\r\ndef" swap matches? ]
60     [ "abc\ndef" swap matches? ]
61     [ "abc\r\n def" swap matches? ] tri
62 ] unit-test
63
64 { t f } [
65     <verbexp> start-of-line tab "abc" then >regexp
66     [ "\tabc" swap matches? ]
67     [ "abc" swap matches? ] bi
68 ] unit-test
69
70 { f } [ "A" <verbexp> start-of-line "a" then >regexp matches? ] unit-test
71 { t t } [
72     <verbexp> start-of-line "a" then case-insensitive >regexp
73     [ "A" swap matches? ]
74     [ "a" swap matches? ] bi
75 ] unit-test
76
77 ! TODO: single-line
78
79 { t } [
80     "https://www.google.com"
81     <verbexp>
82         start-of-line
83         "http" then
84         "s" maybe
85         "://" then
86         "www." maybe
87         " " anything-but
88         end-of-line
89     >regexp matches?
90 ] unit-test
91