]> gitweb.factorcode.org Git - factor.git/blob - basis/regexp/regexp-tests.factor
factor: Retrying on the unit tests. Also normalize some syntax with FUNCTION:.
[factor.git] / basis / regexp / regexp-tests.factor
1 USING: arrays regexp tools.test kernel sequences regexp.parser
2 regexp.private eval strings multiline accessors ;
3 IN: regexp-tests
4
5 { f } [ "b" "a*" <regexp> matches? ] unit-test
6 { t } [ "" "a*" <regexp> matches? ] unit-test
7 { t } [ "a" "a*" <regexp> matches? ] unit-test
8 { t } [ "aaaaaaa" "a*"  <regexp> matches? ] unit-test
9 { f } [ "ab" "a*" <regexp> matches? ] unit-test
10
11 { t } [ "abc" "abc" <regexp> matches? ] unit-test
12 { t } [ "a" "a|b|c" <regexp> matches? ] unit-test
13 { t } [ "b" "a|b|c" <regexp> matches? ] unit-test
14 { t } [ "c" "a|b|c" <regexp> matches? ] unit-test
15 { f } [ "c" "d|e|f" <regexp> matches? ] unit-test
16
17 { t } [ "b" "|b" <regexp> matches? ] unit-test
18 { t } [ "b" "b|" <regexp> matches? ] unit-test
19 { t } [ "" "b|" <regexp> matches? ] unit-test
20 { t } [ "" "b|" <regexp> matches? ] unit-test
21 { t } [ "" "|" <regexp> matches? ] unit-test
22 { t } [ "" "|||||||" <regexp> matches? ] unit-test
23
24 { f } [ "aa" "a|b|c" <regexp> matches? ] unit-test
25 { f } [ "bb" "a|b|c" <regexp> matches? ] unit-test
26 { f } [ "cc" "a|b|c" <regexp> matches? ] unit-test
27 { f } [ "cc" "d|e|f" <regexp> matches? ] unit-test
28
29 { f } [ "" "a+" <regexp> matches? ] unit-test
30 { t } [ "a" "a+" <regexp> matches? ] unit-test
31 { t } [ "aa" "a+" <regexp> matches? ] unit-test
32
33 { t } [ "" "a?" <regexp> matches? ] unit-test
34 { t } [ "a" "a?" <regexp> matches? ] unit-test
35 { f } [ "aa" "a?" <regexp> matches? ] unit-test
36
37 { f } [ "" "." <regexp> matches? ] unit-test
38 { t } [ "a" "." <regexp> matches? ] unit-test
39 { t } [ "." "." <regexp> matches? ] unit-test
40
41 ! Dotall mode -- when on, . matches newlines.
42 ! Off by default.
43 { f } [ "\n" "." <regexp> matches? ] unit-test
44 { t } [ "\n" "(?s:.)" <regexp> matches? ] unit-test
45 { t } [ "\n" R/ ./s matches? ] unit-test
46 { f } [ "\n\n" "(?s:.)." <regexp> matches? ] unit-test
47
48 { f } [ "" ".+" <regexp> matches? ] unit-test
49 { t } [ "a" ".+" <regexp> matches? ] unit-test
50 { t } [ "ab" ".+" <regexp> matches? ] unit-test
51
52 { t } [ " " "[\\s]" <regexp> matches? ] unit-test
53 { f } [ "a" "[\\s]" <regexp> matches? ] unit-test
54 { f } [ " " "[\\S]" <regexp> matches? ] unit-test
55 { t } [ "a" "[\\S]" <regexp> matches? ] unit-test
56 { f } [ " " "[\\w]" <regexp> matches? ] unit-test
57 { t } [ "a" "[\\w]" <regexp> matches? ] unit-test
58 { t } [ " " "[\\W]" <regexp> matches? ] unit-test
59 { f } [ "a" "[\\W]" <regexp> matches? ] unit-test
60
61 { t } [ "/" "\\/" <regexp> matches? ] unit-test
62
63 { t } [ "a" R' a'i matches? ] unit-test
64
65 { t } [ "" "a|b*|c+|d?" <regexp> matches? ] unit-test
66 { t } [ "a" "a|b*|c+|d?" <regexp> matches? ] unit-test
67 { t } [ "c" "a|b*|c+|d?" <regexp> matches? ] unit-test
68 { t } [ "cc" "a|b*|c+|d?" <regexp> matches? ] unit-test
69 { f } [ "ccd" "a|b*|c+|d?" <regexp> matches? ] unit-test
70 { t } [ "d" "a|b*|c+|d?" <regexp> matches? ] unit-test
71
72 { t } [ "foo" "foo|bar" <regexp> matches? ] unit-test
73 { t } [ "bar" "foo|bar" <regexp> matches? ] unit-test
74 { f } [ "foobar" "foo|bar" <regexp> matches? ] unit-test
75
76 { f } [ "" "(a)" <regexp> matches? ] unit-test
77 { t } [ "a" "(a)" <regexp> matches? ] unit-test
78 { f } [ "aa" "(a)" <regexp> matches? ] unit-test
79 { t } [ "aa" "(a*)" <regexp> matches? ] unit-test
80
81 { f } [ "aababaaabbac" "(a|b)+" <regexp> matches? ] unit-test
82 { t } [ "ababaaabba" "(a|b)+" <regexp> matches? ] unit-test
83
84 { f } [ "" "a{1}" <regexp> matches? ] unit-test
85 { t } [ "a" "a{1}" <regexp> matches? ] unit-test
86 { f } [ "aa" "a{1}" <regexp> matches? ] unit-test
87
88 { f } [ "a" "a{2,}" <regexp> matches? ] unit-test
89 { t } [ "aaa" "a{2,}" <regexp> matches? ] unit-test
90 { t } [ "aaaa" "a{2,}" <regexp> matches? ] unit-test
91 { t } [ "aaaaa" "a{2,}" <regexp> matches? ] unit-test
92
93 { t } [ "" "a{,2}" <regexp> matches? ] unit-test
94 { t } [ "a" "a{,2}" <regexp> matches? ] unit-test
95 { t } [ "aa" "a{,2}" <regexp> matches? ] unit-test
96 { f } [ "aaa" "a{,2}" <regexp> matches? ] unit-test
97 { f } [ "aaaa" "a{,2}" <regexp> matches? ] unit-test
98 { f } [ "aaaaa" "a{,2}" <regexp> matches? ] unit-test
99
100 { f } [ "" "a{1,3}" <regexp> matches? ] unit-test
101 { t } [ "a" "a{1,3}" <regexp> matches? ] unit-test
102 { t } [ "aa" "a{1,3}" <regexp> matches? ] unit-test
103 { t } [ "aaa" "a{1,3}" <regexp> matches? ] unit-test
104 { f } [ "aaaa" "a{1,3}" <regexp> matches? ] unit-test
105
106 { f } [ "" "[a]" <regexp> matches? ] unit-test
107 { t } [ "a" "[a]" <regexp> matches? ] unit-test
108 { t } [ "a" "[abc]" <regexp> matches? ] unit-test
109 { f } [ "b" "[a]" <regexp> matches? ] unit-test
110 { f } [ "d" "[abc]" <regexp> matches? ] unit-test
111 { t } [ "ab" "[abc]{1,2}" <regexp> matches? ] unit-test
112 { f } [ "abc" "[abc]{1,2}" <regexp> matches? ] unit-test
113
114 { f } [ "" "[^a]" <regexp> matches? ] unit-test
115 { f } [ "a" "[^a]" <regexp> matches? ] unit-test
116 { f } [ "a" "[^abc]" <regexp> matches? ] unit-test
117 { t } [ "b" "[^a]" <regexp> matches? ] unit-test
118 { t } [ "d" "[^abc]" <regexp> matches? ] unit-test
119 { f } [ "ab" "[^abc]{1,2}" <regexp> matches? ] unit-test
120 { f } [ "abc" "[^abc]{1,2}" <regexp> matches? ] unit-test
121
122 { t } [ "]" "[]]" <regexp> matches? ] unit-test
123 { f } [ "]" "[^]]" <regexp> matches? ] unit-test
124 { t } [ "a" "[^]]" <regexp> matches? ] unit-test
125
126 [ "^" "[^]" <regexp> matches? ] must-fail
127 { t } [ "^" "[]^]" <regexp> matches? ] unit-test
128 { t } [ "]" "[]^]" <regexp> matches? ] unit-test
129
130 { t } [ "[" "[[]" <regexp> matches? ] unit-test
131 { f } [ "^" "[^^]" <regexp> matches? ] unit-test
132 { t } [ "a" "[^^]" <regexp> matches? ] unit-test
133
134 { t } [ "-" "[-]" <regexp> matches? ] unit-test
135 { f } [ "a" "[-]" <regexp> matches? ] unit-test
136 { f } [ "-" "[^-]" <regexp> matches? ] unit-test
137 { t } [ "a" "[^-]" <regexp> matches? ] unit-test
138
139 { t } [ "-" "[-a]" <regexp> matches? ] unit-test
140 { t } [ "a" "[-a]" <regexp> matches? ] unit-test
141 { t } [ "-" "[a-]" <regexp> matches? ] unit-test
142 { t } [ "a" "[a-]" <regexp> matches? ] unit-test
143 { f } [ "b" "[a-]" <regexp> matches? ] unit-test
144 { f } [ "-" "[^-]" <regexp> matches? ] unit-test
145 { t } [ "a" "[^-]" <regexp> matches? ] unit-test
146
147 { f } [ "-" "[a-c]" <regexp> matches? ] unit-test
148 { t } [ "-" "[^a-c]" <regexp> matches? ] unit-test
149 { t } [ "b" "[a-c]" <regexp> matches? ] unit-test
150 { f } [ "b" "[^a-c]" <regexp> matches? ] unit-test
151
152 { t } [ "-" "[a-c-]" <regexp> matches? ] unit-test
153 { f } [ "-" "[^a-c-]" <regexp> matches? ] unit-test
154
155 { t } [ "\\" "[\\\\]" <regexp> matches? ] unit-test
156 { f } [ "a" "[\\\\]" <regexp> matches? ] unit-test
157 { f } [ "\\" "[^\\\\]" <regexp> matches? ] unit-test
158 { t } [ "a" "[^\\\\]" <regexp> matches? ] unit-test
159
160 { t } [ "0" "[\\d]" <regexp> matches? ] unit-test
161 { f } [ "a" "[\\d]" <regexp> matches? ] unit-test
162 { f } [ "0" "[^\\d]" <regexp> matches? ] unit-test
163 { t } [ "a" "[^\\d]" <regexp> matches? ] unit-test
164
165 { t } [ "a" "[a-z]{1,}|[A-Z]{2,4}|b*|c|(f|g)*" <regexp> matches? ] unit-test
166 { t } [ "a" "[a-z]{1,2}|[A-Z]{3,3}|b*|c|(f|g)*" <regexp> matches? ] unit-test
167 { t } [ "a" "[a-z]{1,2}|[A-Z]{3,3}" <regexp> matches? ] unit-test
168
169 { t } [ "1000" "\\d{4,6}" <regexp> matches? ] unit-test
170 { t } [ "1000" "[0-9]{4,6}" <regexp> matches? ] unit-test
171
172 { t } [ "abc" "\\p{Lower}{3}" <regexp> matches? ] unit-test
173 { f } [ "ABC" "\\p{Lower}{3}" <regexp> matches? ] unit-test
174 { t } [ "ABC" "\\p{Upper}{3}" <regexp> matches? ] unit-test
175 { f } [ "abc" "\\p{Upper}{3}" <regexp> matches? ] unit-test
176 { f } [ "abc" "[\\p{Upper}]{3}" <regexp> matches? ] unit-test
177 { t } [ "ABC" "[\\p{Upper}]{3}" <regexp> matches? ] unit-test
178
179 { t } [ "" "\\Q\\E" <regexp> matches? ] unit-test
180 { f } [ "a" "\\Q\\E" <regexp> matches? ] unit-test
181 { t } [ "|*+" "\\Q|*+\\E" <regexp> matches? ] unit-test
182 { f } [ "abc" "\\Q|*+\\E" <regexp> matches? ] unit-test
183 { t } [ "s" "\\Qs\\E" <regexp> matches? ] unit-test
184
185 { t } [ "S" "\\0123" <regexp> matches? ] unit-test
186 { t } [ "SXY" "\\0123XY" <regexp> matches? ] unit-test
187 { t } [ "x" "\\x78" <regexp> matches? ] unit-test
188 { f } [ "y" "\\x78" <regexp> matches? ] unit-test
189 { t } [ "x" "\\u0078" <regexp> matches? ] unit-test
190 { f } [ "y" "\\u0078" <regexp> matches? ] unit-test
191
192 { t } [ "ab" "a+b" <regexp> matches? ] unit-test
193 { f } [ "b" "a+b" <regexp> matches? ] unit-test
194 { t } [ "aab" "a+b" <regexp> matches? ] unit-test
195 { f } [ "abb" "a+b" <regexp> matches? ] unit-test
196
197 { t } [ "abbbb" "ab*" <regexp> matches? ] unit-test
198 { t } [ "a" "ab*" <regexp> matches? ] unit-test
199 { f } [ "abab" "ab*" <regexp> matches? ] unit-test
200
201 { f } [ "x" "\\." <regexp> matches? ] unit-test
202 { t } [ "." "\\." <regexp> matches? ] unit-test
203
204 { t } [ "aaaab" "a+ab" <regexp> matches? ] unit-test
205 { f } [ "aaaxb" "a+ab" <regexp> matches? ] unit-test
206 { t } [ "aaacb" "a+cb" <regexp> matches? ] unit-test
207
208 { "aaa" } [ "aaacb" "a*" <regexp> first-match >string ] unit-test
209 { "aa" } [ "aaacb" "aa?" <regexp> first-match >string ] unit-test
210
211 { t } [ "aaa" R/ AAA/i matches? ] unit-test
212 { f } [ "aax" R/ AAA/i matches? ] unit-test
213 { t } [ "aaa" R/ A*/i matches? ] unit-test
214 { f } [ "aaba" R/ A*/i matches? ] unit-test
215 { t } [ "b" R/ [AB]/i matches? ] unit-test
216 { f } [ "c" R/ [AB]/i matches? ] unit-test
217 { t } [ "c" R/ [A-Z]/i matches? ] unit-test
218 { f } [ "3" R/ [A-Z]/i matches? ] unit-test
219
220 { t } [ "a" "(?i:a)" <regexp> matches? ] unit-test
221 { t } [ "a" "(?i:a)" <regexp> matches? ] unit-test
222 { t } [ "A" "(?i:a)" <regexp> matches? ] unit-test
223 { t } [ "A" "(?i:a)" <regexp> matches? ] unit-test
224
225 { t } [ "a" R/ (?-i:a)/i matches? ] unit-test
226 { t } [ "a" R/ (?-i:a)/i matches? ] unit-test
227 { f } [ "A" R/ (?-i:a)/i matches? ] unit-test
228 { f } [ "A" R/ (?-i:a)/i matches? ] unit-test
229
230 { f } [ "A" "[a-z]" <regexp> matches? ] unit-test
231 { t } [ "A" R/ [a-z]/i matches? ] unit-test
232
233 { f } [ "A" "\\p{Lower}" <regexp> matches? ] unit-test
234 { t } [ "A" R/ \p{Lower}/i matches? ] unit-test
235
236 { t } [ "abc" R/ abc/r matches? ] unit-test
237 { t } [ "abc" R/ a[bB][cC]/r matches? ] unit-test
238
239 { t } [ 3 "xabc" R/ abc/r match-index-from >boolean ] unit-test
240 { t } [ 3 "xabc" R/ a[bB][cC]/r match-index-from >boolean ] unit-test
241
242 { 2 } [ 0 "llamallol" R/ ll/ match-index-from ] unit-test
243 { 5 } [ 8 "lolmallol" R/ lol/r match-index-from ] unit-test
244
245 { t } [ "s@f" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
246 { f } [ "a" "[a-z.-]@[a-z]" <regexp> matches? ] unit-test
247 { t } [ ".o" "\\.[a-z]" <regexp> matches? ] unit-test
248
249 { t } [ "abc*" "[^\\*]*\\*" <regexp> matches? ] unit-test
250 { t } [ "bca" "[^a]*a" <regexp> matches? ] unit-test
251
252 { } [
253     "(0[lL]?|[1-9]\\d{0,9}(\\d{0,9}[lL])?|0[xX]\\p{XDigit}{1,8}(\\p{XDigit}{0,8}[lL])?|0[0-7]{1,11}([0-7]{0,11}[lL])?|([0-9]+\\.[0-9]*|\\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?|[0-9]+([eE][+-]?[0-9]+[fFdD]?|([eE][+-]?[0-9]+)?[fFdD]))"
254     <regexp> drop
255 ] unit-test
256
257 { } [ "(\\$[\\p{XDigit}]|[\\p{Digit}])" <regexp> drop ] unit-test
258
259 ! Comment inside a regular expression
260 { t } [ "ac" "a(?#boo)c" <regexp> matches? ] unit-test
261
262 { } [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval( -- ) ] unit-test
263
264 { } [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval( -- ) ] unit-test
265
266 { } [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval( -- ) ] unit-test
267
268 { "ab" } [ "ab" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
269 { "abc" } [ "abc" "(a|ab)(bc)?" <regexp> first-match >string ] unit-test
270
271 { "ab" } [ "ab" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
272 { "abc" } [ "abc" "(ab|a)(bc)?" <regexp> first-match >string ] unit-test
273
274 { "b" } [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" <regexp> first-match >string ] unit-test
275
276 { T{ slice { from 5 } { to 10 } { seq "hellohello" } } }
277 [ "hellohello" R/ hello/r first-match ]
278 unit-test
279
280 { { "1" "2" "3" "4" } }
281 [ "1ABC2DEF3GHI4" R/ [A-Z]+/ re-split [ >string ] map ] unit-test
282
283 { { "1" "2" "3" "4" "" } }
284 [ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ re-split [ >string ] map ] unit-test
285
286 { { "" } } [ "" R/ =/ re-split [ >string ] map ] unit-test
287
288 { { "a" "" } } [ "a=" R/ =/ re-split [ >string ] map ] unit-test
289
290 { { "he" "o" } } [ "hello" R/ l+/ re-split [ >string ] map ] unit-test
291
292 { { "h" "llo" } } [ "hello" R/ e+/ re-split [ >string ] map ] unit-test
293
294 { { "" "h" "" "l" "l" "o" "" } } [ "hello" R/ e*/ re-split [ >string ] map ] unit-test
295
296 { { { 0 5 "hellohello" } { 5 10 "hellohello" } } }
297 [ "hellohello" R/ hello/ [ 3array ] map-matches ]
298 unit-test
299
300 { { { 5 10 "hellohello" } { 0 5 "hellohello" } } }
301 [ "hellohello" R/ hello/r [ 3array ] map-matches ]
302 unit-test
303
304 { { "ABC" "DEF" "GHI" } }
305 [ "1ABC2DEF3GHI4" R/ [A-Z]+/ all-matching-subseqs ] unit-test
306
307 { { "ee" "e" } } [ "heellohello" R/ e+/ all-matching-subseqs ] unit-test
308 { { "e" "ee" } } [ "heellohello" R/ e+/r all-matching-subseqs ] unit-test
309
310 { 3 } [ "1ABC2DEF3GHI4" R/ [A-Z]+/ count-matches ] unit-test
311
312 { 3 } [ "1ABC2DEF3GHI4" R/ [A-Z]+/r count-matches ] unit-test
313
314 { 1 } [ "" R/ / count-matches ] unit-test
315
316 { 1 } [ "" R/ /r count-matches ] unit-test
317
318 { 0 } [ "123" R/ [A-Z]+/ count-matches ] unit-test
319
320 { 0 } [ "123" R/ [A-Z]+/r count-matches ] unit-test
321
322 { 6 } [ "hello" R/ e*/ count-matches ] unit-test
323
324 { 6 } [ "hello" R/ e*/r count-matches ] unit-test
325
326 { 11 } [ "hello world" R/ l*/ count-matches ] unit-test
327
328 { 11 } [ "hello world" R/ l*/r count-matches ] unit-test
329
330 { 1 } [ "hello" R/ e+/ count-matches ] unit-test
331
332 { 2 } [ "hello world" R/ l+/r count-matches ] unit-test
333
334 { "1.2.3.4." } [ "1ABC2DEF3GHI4JK" R/ [A-Z]+/ "." re-replace ] unit-test
335 { "XhXXlXlXoX XwXoXrXlXdX" } [ "hello world" R/ e*/ "X" re-replace ] unit-test
336 { "-- title --" } [ "== title ==" R/ =/ "-" re-replace ] unit-test
337
338 { "" } [ "ab" "a(?!b)" <regexp> first-match >string ] unit-test
339 { "a" } [ "ac" "a(?!b)" <regexp> first-match >string ] unit-test
340 { t } [ "fxxbar" ".{3}(?!foo)bar" <regexp> matches? ] unit-test
341 { t } [ "foobar" ".{3}(?!foo)bar" <regexp> matches? ] unit-test
342 { t } [ "fxxbar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
343 { f } [ "foobar" "(?!foo).{3}bar" <regexp> matches? ] unit-test
344 { "a" } [ "ab" "a(?=b)(?=b)" <regexp> first-match >string ] unit-test
345 { "a" } [ "ba" "(?<=b)(?<=b)a" <regexp> first-match >string ] unit-test
346 { "a" } [ "cab" "(?<=c)a(?=b)" <regexp> first-match >string ] unit-test
347
348 { 3 } [ "foobar" "foo(?=bar)" <regexp> first-match length ] unit-test
349 { f } [ "foobxr" "foo(?=bar)" <regexp> first-match ] unit-test
350
351 ! Bug in parsing word
352 { t } [ "a" R' a' matches? ] unit-test
353
354 ! Testing negation
355 { f } [ "a" R/ (?~a)/ matches? ] unit-test
356 { t } [ "aa" R/ (?~a)/ matches? ] unit-test
357 { t } [ "bb" R/ (?~a)/ matches? ] unit-test
358 { t } [ "" R/ (?~a)/ matches? ] unit-test
359
360 { f } [ "a" R/ (?~a+|b)/ matches? ] unit-test
361 { f } [ "aa" R/ (?~a+|b)/ matches? ] unit-test
362 { t } [ "bb" R/ (?~a+|b)/ matches? ] unit-test
363 { f } [ "b" R/ (?~a+|b)/ matches? ] unit-test
364 { t } [ "" R/ (?~a+|b)/ matches? ] unit-test
365
366 ! Intersecting classes
367 { t } [ "ab" R/ ac|\p{Lower}b/ matches? ] unit-test
368 { t } [ "ab" R/ ac|[a-z]b/ matches? ] unit-test
369 { t } [ "ac" R/ ac|\p{Lower}b/ matches? ] unit-test
370 { t } [ "ac" R/ ac|[a-z]b/ matches? ] unit-test
371 { t } [ "ac" R/ [a-zA-Z]c|\p{Lower}b/ matches? ] unit-test
372 { t } [ "ab" R/ [a-zA-Z]c|\p{Lower}b/ matches? ] unit-test
373 { t } [ "πb" R/ [a-zA-Z]c|\p{Lower}b/ matches? ] unit-test
374 { f } [ "πc" R/ [a-zA-Z]c|\p{Lower}b/ matches? ] unit-test
375 { f } [ "Ab" R/ [a-zA-Z]c|\p{Lower}b/ matches? ] unit-test
376
377 { t } [ "aaaa" R/ .*a./ matches? ] unit-test
378
379 { f } [ "ab" R/ (?~ac|\p{Lower}b)/ matches? ] unit-test
380 { f } [ "ab" R/ (?~ac|[a-z]b)/ matches? ] unit-test
381 { f } [ "ac" R/ (?~ac|\p{Lower}b)/ matches? ] unit-test
382 { f } [ "ac" R/ (?~ac|[a-z]b)/ matches? ] unit-test
383 { f } [ "ac" R/ (?~[a-zA-Z]c|\p{Lower}b)/ matches? ] unit-test
384 { f } [ "ab" R/ (?~[a-zA-Z]c|\p{Lower}b)/ matches? ] unit-test
385 { f } [ "πb" R/ (?~[a-zA-Z]c|\p{Lower}b)/ matches? ] unit-test
386 { t } [ "πc" R/ (?~[a-zA-Z]c|\p{Lower}b)/ matches? ] unit-test
387 { t } [ "Ab" R/ (?~[a-zA-Z]c|\p{Lower}b)/ matches? ] unit-test
388
389 ! DFA is compiled when needed, or when literal
390 { regexp-initial-word } [ "foo" <regexp> dfa>> ] unit-test
391 { f } [ R/ foo/ dfa>> \ regexp-initial-word = ] unit-test
392
393 { t } [ "a" R/ ^a/ matches? ] unit-test
394 { f } [ "\na" R/ ^a/ matches? ] unit-test
395 { f } [ "\r\na" R/ ^a/ matches? ] unit-test
396 { f } [ "\ra" R/ ^a/ matches? ] unit-test
397
398 { 1 } [ "a" R/ ^a/ count-matches ] unit-test
399 { 0 } [ "\na" R/ ^a/ count-matches ] unit-test
400 { 0 } [ "\r\na" R/ ^a/ count-matches ] unit-test
401 { 0 } [ "\ra" R/ ^a/ count-matches ] unit-test
402
403 { t } [ "a" R/ a$/ matches? ] unit-test
404 { f } [ "a\n" R/ a$/ matches? ] unit-test
405 { f } [ "a\r" R/ a$/ matches? ] unit-test
406 { f } [ "a\r\n" R/ a$/ matches? ] unit-test
407
408 { 1 } [ "a" R/ a$/ count-matches ] unit-test
409 { 0 } [ "a\n" R/ a$/ count-matches ] unit-test
410 { 0 } [ "a\r" R/ a$/ count-matches ] unit-test
411 { 0 } [ "a\r\n" R/ a$/ count-matches ] unit-test
412
413 { t } [ "a" R/ a$|b$/ matches? ] unit-test
414 { t } [ "b" R/ a$|b$/ matches? ] unit-test
415 { f } [ "ab" R/ a$|b$/ matches? ] unit-test
416 { t } [ "ba" R/ ba$|b$/ matches? ] unit-test
417
418 { t } [ "a" R/ \Aa/ matches? ] unit-test
419 { f } [ "\na" R/ \Aaa/ matches? ] unit-test
420 { f } [ "\r\na" R/ \Aa/ matches? ] unit-test
421 { f } [ "\ra" R/ \Aa/ matches? ] unit-test
422
423 { t } [ "a" R/ \Aa/m matches? ] unit-test
424 { f } [ "\na" R/ \Aaa/m matches? ] unit-test
425 { f } [ "\r\na" R/ \Aa/m matches? ] unit-test
426 { f } [ "\ra" R/ \Aa/m matches? ] unit-test
427 { 0 } [ "\ra" R/ \Aa/m count-matches ] unit-test
428
429 { f } [ "\r\n\n\n\nam" R/ ^am/m matches? ] unit-test
430 { 1 } [ "\r\n\n\n\nam" R/ ^am/m count-matches ] unit-test
431
432 { t } [ "a" R/ \Aa\z/m matches? ] unit-test
433 { f } [ "a\n" R/ \Aa\z/m matches? ] unit-test
434
435 { f } [ "a\r\n" R/ \Aa\Z/m matches? ] unit-test
436 { f } [ "a\n" R/ \Aa\Z/m matches? ] unit-test
437 { 1 } [ "a\r\n" R/ \Aa\Z/m count-matches ] unit-test
438 { 1 } [ "a\n" R/ \Aa\Z/m count-matches ] unit-test
439
440 { t } [ "a" R/ \Aa\Z/m matches? ] unit-test
441 { f } [ "\na" R/ \Aaa\Z/m matches? ] unit-test
442 { f } [ "\r\na" R/ \Aa\Z/m matches? ] unit-test
443 { f } [ "\ra" R/ \Aa\Z/m matches? ] unit-test
444
445 { 1 } [ "a" R/ \Aa\Z/m count-matches ] unit-test
446 { 0 } [ "\na" R/ \Aaa\Z/m count-matches ] unit-test
447 { 0 } [ "\r\na" R/ \Aa\Z/m count-matches ] unit-test
448 { 0 } [ "\ra" R/ \Aa\Z/m count-matches ] unit-test
449
450 { t } [ "a" R/ ^a/m matches? ] unit-test
451 { f } [ "\na" R/ ^a/m matches? ] unit-test
452 { 1 } [ "\na" R/ ^a/m count-matches ] unit-test
453 { 1 } [ "\r\na" R/ ^a/m count-matches ] unit-test
454 { 1 } [ "\ra" R/ ^a/m count-matches ] unit-test
455
456 { t } [ "a" R/ a$/m matches? ] unit-test
457 { f } [ "a\n" R/ a$/m matches? ] unit-test
458 { 1 } [ "a\n" R/ a$/m count-matches ] unit-test
459 { 1 } [ "a\r" R/ a$/m count-matches ] unit-test
460 { 1 } [ "a\r\n" R/ a$/m count-matches ] unit-test
461
462 { f } [ "foobxr" "foo\\z" <regexp> first-match ] unit-test
463 { 3 } [ "foo" "foo\\z" <regexp> first-match length ] unit-test
464
465 { t } [ "a foo b" R/ foo/ re-contains? ] unit-test
466 { f } [ "a bar b" R/ foo/ re-contains? ] unit-test
467 { t } [ "foo" R/ foo/ re-contains? ] unit-test
468
469 { { "foo" "fxx" "fab" } } [ "fab fxx foo" R/ f../r all-matching-subseqs ] unit-test
470
471 { t } [ "foo" "\\bfoo\\b" <regexp> re-contains? ] unit-test
472 { t } [ "afoob" "\\Bfoo\\B" <regexp> re-contains? ] unit-test
473 { f } [ "afoob" "\\bfoo\\b" <regexp> re-contains? ] unit-test
474 { f } [ "foo" "\\Bfoo\\B" <regexp> re-contains? ] unit-test
475
476 { 3 } [ "foo bar" "foo\\b" <regexp> first-match length ] unit-test
477 { f } [ "fooxbar" "foo\\b" <regexp> re-contains? ] unit-test
478 { t } [ "foo" "foo\\b" <regexp> re-contains? ] unit-test
479 { t } [ "foo bar" "foo\\b bar" <regexp> matches? ] unit-test
480 { f } [ "fooxbar" "foo\\bxbar" <regexp> matches? ] unit-test
481 { f } [ "foo" "foo\\bbar" <regexp> matches? ] unit-test
482
483 { f } [ "foo bar" "foo\\B" <regexp> re-contains? ] unit-test
484 { 3 } [ "fooxbar" "foo\\B" <regexp> first-match length ] unit-test
485 { f } [ "foo" "foo\\B" <regexp> re-contains? ] unit-test
486 { f } [ "foo bar" "foo\\B bar" <regexp> matches? ] unit-test
487 { t } [ "fooxbar" "foo\\Bxbar" <regexp> matches? ] unit-test
488 { f } [ "foo" "foo\\Bbar" <regexp> matches? ] unit-test
489
490 { t } [ "ab" "a(?=b*)" <regexp> re-contains? ] unit-test
491 { t } [ "abbbbbc" "a(?=b*c)" <regexp> re-contains? ] unit-test
492 { f } [ "abbbbb" "a(?=b*c)" <regexp> re-contains? ] unit-test
493 { t } [ "ab" "a(?=b*)" <regexp> re-contains? ] unit-test
494
495 { "az" } [ "baz" "(?<=b)(az)" <regexp> first-match >string ] unit-test
496 { f } [ "chaz" "(?<=b)(az)" <regexp> re-contains? ] unit-test
497 { "a" } [ "cbaz" "(?<=b*)a" <regexp> first-match >string ] unit-test
498 { f } [ "baz" "a(?<=b)" <regexp> re-contains? ] unit-test
499
500 { f } [ "baz" "(?<!b)a" <regexp> re-contains? ] unit-test
501 { t } [ "caz" "(?<!b)a" <regexp> re-contains? ] unit-test
502
503 { "abcd" } [ "abcdefg" "a(?=bcdefg)bcd" <regexp> first-match >string ] unit-test
504 { t } [ "abcdefg" "a(?#bcdefg)bcd" <regexp> re-contains? ] unit-test
505 { t } [ "abcdefg" "a(?:bcdefg)" <regexp> matches? ] unit-test
506
507 { 3 } [ "caba" "(?<=b)a" <regexp> first-match from>> ] unit-test
508
509 { t } [ "\ra" R/ .^a/ms matches? ] unit-test
510 { f } [ "\ra" R/ .^a/mds matches? ] unit-test
511 { t } [ "\na" R/ .^a/ms matches? ] unit-test
512 { t } [ "\na" R/ .^a/mds matches? ] unit-test
513
514 { t } [ "a\r" R/ a$./ms matches? ] unit-test
515 { f } [ "a\r" R/ a$./mds matches? ] unit-test
516 { t } [ "a\n" R/ a$./ms matches? ] unit-test
517 { t } [ "a\n" R/ a$./mds matches? ] unit-test
518
519 ! Unicode categories
520 { t } [ "a" R/ \p{L}/ matches? ] unit-test
521 { t } [ "A" R/ \p{L}/ matches? ] unit-test
522 { f } [ " " R/ \p{L}/ matches? ] unit-test
523 { f } [ "a" R/ \P{L}/ matches? ] unit-test
524 { f } [ "A" R/ \P{L}/ matches? ] unit-test
525 { t } [ " " R/ \P{L}/ matches? ] unit-test
526
527 { t } [ "a" R/ \p{Ll}/ matches? ] unit-test
528 { f } [ "A" R/ \p{Ll}/ matches? ] unit-test
529 { f } [ " " R/ \p{Ll}/ matches? ] unit-test
530 { f } [ "a" R/ \P{Ll}/ matches? ] unit-test
531 { t } [ "A" R/ \P{Ll}/ matches? ] unit-test
532 { t } [ " " R/ \P{Ll}/ matches? ] unit-test
533
534 { t } [ "a" R/ \p{script=Latin}/ matches? ] unit-test
535 { f } [ " " R/ \p{script=Latin}/ matches? ] unit-test
536 { f } [ "a" R/ \P{script=Latin}/ matches? ] unit-test
537 { t } [ " " R/ \P{script=Latin}/ matches? ] unit-test
538
539 ! These should be case-insensitive
540 { f } [ " " R/ \p{l}/ matches? ] unit-test
541 { f } [ "a" R/ \P{l}/ matches? ] unit-test
542 { f } [ "a" R/ \P{ll}/ matches? ] unit-test
543 { t } [ " " R/ \P{LL}/ matches? ] unit-test
544 { f } [ "a" R/ \P{sCriPt = latin}/ matches? ] unit-test
545 { t } [ " " R/ \P{SCRIPT = laTIn}/ matches? ] unit-test
546
547 ! Logical operators
548 { t } [ "a" R/ [\p{script=latin}\p{lower}]/ matches? ] unit-test
549 { t } [ "π" R/ [\p{script=latin}\p{lower}]/ matches? ] unit-test
550 { t } [ "A" R/ [\p{script=latin}\p{lower}]/ matches? ] unit-test
551 { f } [ "3" R/ [\p{script=latin}\p{lower}]/ matches? ] unit-test
552
553 { t } [ "a" R/ [\p{script=latin}||\p{lower}]/ matches? ] unit-test
554 { t } [ "π" R/ [\p{script=latin}||\p{lower}]/ matches? ] unit-test
555 { t } [ "A" R/ [\p{script=latin}||\p{lower}]/ matches? ] unit-test
556 { f } [ "3" R/ [\p{script=latin}||\p{lower}]/ matches? ] unit-test
557
558 { t } [ "a" R/ [\p{script=latin}&&\p{lower}]/ matches? ] unit-test
559 { f } [ "π" R/ [\p{script=latin}&&\p{lower}]/ matches? ] unit-test
560 { f } [ "A" R/ [\p{script=latin}&&\p{lower}]/ matches? ] unit-test
561 { f } [ "3" R/ [\p{script=latin}&&\p{lower}]/ matches? ] unit-test
562
563 { f } [ "a" R/ [\p{script=latin}~~\p{lower}]/ matches? ] unit-test
564 { t } [ "π" R/ [\p{script=latin}~~\p{lower}]/ matches? ] unit-test
565 { t } [ "A" R/ [\p{script=latin}~~\p{lower}]/ matches? ] unit-test
566 { f } [ "3" R/ [\p{script=latin}~~\p{lower}]/ matches? ] unit-test
567
568 { f } [ "a" R/ [\p{script=latin}--\p{lower}]/ matches? ] unit-test
569 { f } [ "π" R/ [\p{script=latin}--\p{lower}]/ matches? ] unit-test
570 { t } [ "A" R/ [\p{script=latin}--\p{lower}]/ matches? ] unit-test
571 { f } [ "3" R/ [\p{script=latin}--\p{lower}]/ matches? ] unit-test
572
573 { t } [ " " R/ \P{alpha}/ matches? ] unit-test
574 { f } [ "" R/ \P{alpha}/ matches? ] unit-test
575 { f } [ "a " R/ \P{alpha}/ matches? ] unit-test
576 { f } [ "a" R/ \P{alpha}/ matches? ] unit-test