1 USING: accessors arrays assocs continuations http.client kernel
2 literals math math.parser ranges pcre pcre.ffi pcre.private
3 random sequences system tools.test ;
8 { { "Bords" "words" "word" } } [
9 "Bords, words, word." { ", " ", " "." } split-subseqs
12 { { { 3 "day" } { 2 "month" } { 1 "year" } } } [
13 "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
14 <compiled-pcre> nametable>>
17 CONSTANT: iso-date "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
19 ! On windows the erroffset appears to be set to 0 despite there being
20 ! nothing wrong with the regexp.
22 "foo" (pcre) 3array rest { { f -1 } { f 0 } } member?
27 { "year" "month" "day" } [ pcre_get_stringnumber ] with map
31 "foo" <compiled-pcre> PCRE_UTF8 has-option?
34 ! This option is not present on old PCRE versions.
36 "foo" <compiled-pcre> version 8.10 >
37 [ PCRE_UCP has-option? ] [ PCRE_UCP has-option? not ] if
40 os unix? [ [ 10 ] [ PCRE_CONFIG_NEWLINE pcre-config ] unit-test ] when
42 ! In this day and age, not supporting utf-8 is broken.
43 { 1 } [ PCRE_CONFIG_UTF8 pcre-config ] unit-test
45 { 1 } [ PCRE_CONFIG_UNICODE_PROPERTIES pcre-config ] unit-test
47 ! Ok if these options throw if the pcre library is to old to support
48 ! these configuration parameters.
50 [ PCRE_CONFIG_UTF16 pcre-config ] [ what>> ] recover
51 { 0 $ PCRE_CONFIG_UTF16 } member?
54 [ PCRE_CONFIG_UTF32 pcre-config ] [ what>> ] recover
55 { 0 $ PCRE_CONFIG_UTF32 } member?
60 [ "foo" <pcre> f 33 pcre-fullinfo ] [ what>> ] recover
65 { { f "1999-01-12" } { "year" "1999" } { "month" "01" } { "day" "12" } }
67 "1999-01-12" iso-date <compiled-pcre> findall first
71 "2003-10-09 1999-09-01 1514-10-20" iso-date <compiled-pcre> findall length
74 { 5 } [ "abcdef" "[a-e]" findall length ] unit-test
76 { 3 } [ "foo bar baz" "foo|bar|baz" findall length ] unit-test
78 { 3 } [ "örjan är åtta" "[åäö]" findall length ] unit-test
80 { 3 } [ "ÅÄÖ" "\\p{Lu}" findall length ] unit-test
82 { 3 } [ "foobar" "foo(?=bar)" findall first first second length ] unit-test
84 { { { { f ", " } } { { f ", " } } { { f "." } } } } [
85 "Words, words, word." "\\W+" findall
88 { { ", " ", " "." } } [
89 "Words, words, word." "\\W+" findall [ first second ] map
92 : long-string ( -- x )
93 10000 [ CHAR: a CHAR: z [a..b] random ] "" replicate-as ;
96 { 0 } [ long-string ".{0,15}foobar.{0,10}" findall length ] unit-test
98 ! Empty matches, corner case behavior is copied from pcredemo.c
99 { { { { f "foo" } } { { f "" } } } }
100 [ "foo" ".*" findall ] unit-test
102 { { { { f "" } } { { f "" } } { { f "" } } } }
103 [ "foo" "B*" findall ] unit-test
105 ! Empty matches in strings with multi-byte characters are tricky.
106 { { { { f "" } } { { f "" } } { { f "" } } { { f "" } } } }
107 [ "öööö" "x*" findall ] unit-test
110 { t } [ "örjan" "örjan" matches? ] unit-test
112 { t } [ "abcö" "\\p{Ll}{4}" matches? ] unit-test
114 ! This used to work in 8.36, but might have changed in later versions.
115 ! See: https://bugs.exim.org/show_bug.cgi?id=1875
118 "(?s)." <compiled-pcre> PCRE_DOTALL has-option?
119 "(?i)x" <compiled-pcre> PCRE_CASELESS has-option?
123 { f } [ "\n" "." matches? ] unit-test
124 { t } [ "\n" "(?s)." matches? ] unit-test
127 "hello\nthere" "^.*$" <compiled-pcre> matches?
128 "hello\nthere" "(?s)^.*$" <compiled-pcre> matches?
131 ! Modes off by default
134 "x" <compiled-pcre> PCRE_CASELESS has-option?
136 "." <compiled-pcre> PCRE_DOTALL has-option?
141 { "response and responsibility" "sense and responsibility" }
142 [ "(sens|respons)e and \\1ibility" matches? ] map
146 { "rah rah" "RAH RAH" "RAH rah" } [ "((?i)rah)\\s+\\1" matches? ] map
150 { { { "Words" "words" "word" } { "Words" "words" "word" } } } [
151 "Words, words, word." { "\\W+" "[,. ]" } [ split ] with map
156 "https://factorcode.org/" http-get nip
157 "href=\"(?P<link>[^\"]+)\"" findall [ "link" of ] map sequence?
160 ! Test that the regexp syntax works.
161 { t } [ "1234abcd" regexp:R/ ^\d+\w+$/ matches? ] unit-test