1 USING: accessors arrays assocs continuations http.client kernel
2 literals math.ranges pcre pcre.ffi pcre.private random sequences
7 [ { "Bords" "words" "word" } ] [
8 "Bords, words, word." { ", " ", " "." } split-subseqs
11 [ { { 3 "day" } { 2 "month" } { 1 "year" } } ] [
12 "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
13 <compiled-pcre> nametable>>
16 CONSTANT: iso-date "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"
18 ! On windows the erroffset appears to be set to 0 despite there being
19 ! nothing wrong with the regexp.
21 "foo" (pcre) 3array rest { { f -1 } { f 0 } } member?
26 { "year" "month" "day" } [ pcre_get_stringnumber ] with map
29 [ t ] [ "foo" <compiled-pcre> PCRE_UTF8 has-option? ] unit-test
31 os unix? [ [ 10 ] [ PCRE_CONFIG_NEWLINE pcre-config ] unit-test ] when
33 ! In this day and age, not supporting utf-8 is broken.
34 [ 1 ] [ PCRE_CONFIG_UTF8 pcre-config ] unit-test
36 [ 1 ] [ PCRE_CONFIG_UNICODE_PROPERTIES pcre-config ] unit-test
38 ! Ok if these options throw if the pcre library is to old to support
39 ! these configuration parameters.
41 [ PCRE_CONFIG_UTF16 pcre-config ] [ what>> ] recover
42 { 0 $ PCRE_CONFIG_UTF16 } member?
45 [ PCRE_CONFIG_UTF32 pcre-config ] [ what>> ] recover
46 { 0 $ PCRE_CONFIG_UTF32 } member?
51 { { f "1999-01-12" } { "year" "1999" } { "month" "01" } { "day" "12" } }
53 "1999-01-12" iso-date <compiled-pcre> findall first
57 "2003-10-09 1999-09-01 1514-10-20" iso-date <compiled-pcre> findall length
60 [ 5 ] [ "abcdef" "[a-e]" findall length ] unit-test
62 [ 3 ] [ "foo bar baz" "foo|bar|baz" findall length ] unit-test
64 [ 3 ] [ "örjan är åtta" "[åäö]" findall length ] unit-test
66 [ 3 ] [ "ÅÄÖ" "\\p{Lu}" findall length ] unit-test
68 [ 3 ] [ "foobar" "foo(?=bar)" findall first first second length ] unit-test
70 [ { { { f ", " } } { { f ", " } } { { f "." } } } ] [
71 "Words, words, word." "\\W+" findall
74 [ { ", " ", " "." } ] [
75 "Words, words, word." "\\W+" findall [ first second ] map
78 : long-string ( -- x )
79 10000 [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
82 [ 0 ] [ long-string ".{0,15}foobar.{0,10}" findall length ] unit-test
84 ! Empty matches, corner case behaviour is copied from pcredemo.c
85 [ { { { f "foo" } } { { f "" } } } ]
86 [ "foo" ".*" findall ] unit-test
88 [ { { { f "" } } { { f "" } } { { f "" } } } ]
89 [ "foo" "B*" findall ] unit-test
91 ! Empty matches in strings with multi-byte characters are tricky.
92 [ { { { f "" } } { { f "" } } { { f "" } } { { f "" } } } ]
93 [ "öööö" "x*" findall ] unit-test
96 [ t ] [ "örjan" "örjan" matches? ] unit-test
98 [ t ] [ "abcö" "\\p{Ll}{4}" matches? ] unit-test
100 ! Dotall mode, off by default
101 [ f ] [ "." <compiled-pcre> PCRE_DOTALL has-option? ] unit-test
102 [ t ] [ "(?s)." <compiled-pcre> PCRE_DOTALL has-option? ] unit-test
104 [ f ] [ "\n" "." matches? ] unit-test
105 [ t ] [ "\n" "(?s)." matches? ] unit-test
107 ! Caseless mode, off by default
109 { "x" "(?i)x" } [ <compiled-pcre> PCRE_CASELESS has-option? ] map
114 { "response and responsibility" "sense and responsibility" }
115 [ "(sens|respons)e and \\1ibility" matches? ] map
119 { "rah rah" "RAH RAH" "RAH rah" } [ "((?i)rah)\\s+\\1" matches? ] map
123 [ { { "Words" "words" "word" } { "Words" "words" "word" } } ] [
124 "Words, words, word." { "\\W+" "[,. ]" } [ split ] with map
129 "http://factorcode.org/" http-get nip
130 "href=\"(?P<link>[^\"]+)\"" findall [ "link" of ] map sequence?
133 ! Test that the regexp syntax works.
134 [ t ] [ "1234abcd" regexp:R[ ^\d+\w+$] matches? ] unit-test