1\ Copyright (c) 2006-2019 Michael Scholz <mi-scholz@users.sourceforge.net>
2\ All rights reserved.
3\
4\ Redistribution and use in source and binary forms, with or without
5\ modification, are permitted provided that the following conditions
6\ are met:
7\ 1. Redistributions of source code must retain the above copyright
8\    notice, this list of conditions and the following disclaimer.
9\ 2. Redistributions in binary form must reproduce the above copyright
10\    notice, this list of conditions and the following disclaimer in the
11\    documentation and/or other materials provided with the distribution.
12\
13\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23\ SUCH DAMAGE.
24\
25\ @(#)regexp-test.fs	1.18 11/28/19
26
27'regexp provided? [unless] skip-file [then]
28
29require test-utils.fs
30
31: regexp-test ( -- )
32	\ regexp?
33	"x" make-regexp regexp? not "regexp? (1)" test-expr
34	/^s/ regexp? not "regexp? (2)" test-expr
35	nil  regexp? "regexp? (3)" test-expr
36	\ make-regexp
37	"(bar)"  make-regexp { re1 }
38	"(B|b)+" make-regexp { re2 }
39	re1 regexp? not "re1 make-regexp not" test-expr
40	re2 regexp? not "re2 make-regexp not" test-expr
41	\ regexp-match (alias regexp= and re=)
42	re1 "foobar" regexp-match { match }
43	match not "regexp-match (1)" test-expr
44	match fixnum? not "regexp-match (2)" test-expr
45	re/ (aa*)(b*)(c*)/ "aaabbbccc" regexp-match 9 <>
46	    "regexp-match (3)" test-expr
47	*re0* "aaabbbccc" string<> "*re0* (1)" test-expr
48	*re1* "aaa"       string<> "*re1* (1)" test-expr
49	*re2* "bbb"       string<> "*re2* (1)" test-expr
50	*re3* "ccc"       string<> "*re3* (1)" test-expr
51	/foo/ "foobar" regexp-match 3 <> "regexp-match (4)" test-expr
52	re1 "foobar" regexp-match 3 <> "regexp-match (5)" test-expr
53	/.*(bar)/ "foobar" regexp-match 6 <> "regexp-match (6)" test-expr
54	*re0* "foobar" string<> "*re0* (2)" test-expr
55	*re1* "bar"    string<> "*re1* (2)" test-expr
56	*re2* #f             <> "*re2* (2)" test-expr
57	\ regexp-search
58	re1 "foobar" regexp-search 3 <> "regexp-search (1)" test-expr
59	re2 "foobar" regexp-search 3 <> "regexp-search (2)" test-expr
60	/foo/ "foobar" :start 0 :range 6 regexp-search not
61	    "regexp-search (3)" test-expr
62	re1 "foobar" :start 0 :range 2 regexp-search
63	    "regexp-search (4)" test-expr
64	re1 "foobar" :start 3 :range 2 regexp-search 3 <>
65	    "regexp-search (5)" test-expr
66	re1 0 apply "bar" string<> "re1 0 apply 'bar' not" test-expr
67	re1 1 apply "bar" string<> "re1 1 apply 'bar' not" test-expr
68	re1 2 apply #f          <> "re1 2 apply #f not"    test-expr
69	re2 "foobar" regexp-search 3 <> "regexp-search (6)" test-expr
70	\ regexp-replace
71	/bar/ "foobar" "BAR" regexp-replace "fooBAR" string<>
72	    "regexp-replace (1)" test-expr
73	/(foo)/ "foo-bar" "***\\1***" regexp-replace
74	    "***foo***-bar" string<>
75	    "regexp-replace (2)" test-expr
76	/(fo(O|o))/ "bar-foo-bar" "***\\0***\\1***\\2***" regexp-replace
77	    "bar-***foo***foo***o***-bar" string<>
78	    "regexp-replace (3)" test-expr
79	/(foo)/ "foo-bar" "***\\2***" <'> regexp-replace
80	    'regexp-error dup fth-catch 'regexp-error <>
81	    "regexp-replace (4)" test-expr
82	stack-reset
83	/(foo)/ "foo-bar" "***\\***" <'> regexp-replace
84	    'regexp-error dup fth-catch 'regexp-error <>
85	    "regexp-replace (5)" test-expr
86	stack-reset
87	\ re-match
88	/a*/ "aaaaab" 0 re-match 5 <> "/a*/ 0 re-match 5 <>" test-expr
89	/a*/ "aaaaab" 2 re-match 3 <> "/a*/ 2 re-match 3 <>" test-expr
90	/a*/ "aaaaab" 5 re-match 0 <> "/a*/ 5 re-match 0 <>" test-expr
91	/a*/ "aaaaab" 6 re-match 0 <> "/a*/ 6 re-match 0 <>" test-expr
92	\ re-search
93	/a*/ "aaaaab" 0 1 re-search 0 <> "/a*/ 0 1 re-search 0 <>" test-expr
94	/a*/ "aaaaab" 2 4 re-search 2 <> "/a*/ 2 4 re-search 2 <>" test-expr
95;
96
97*fth-test-count* 0 [do] regexp-test [loop]
98
99\ regexp-test.fs ends here
100