aboutsummaryrefslogtreecommitdiff
path: root/src/test/modules/test_regex/sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-02-17 12:24:12 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-02-17 12:24:23 -0500
commit4e703d67193df0431c0740044d662d1feade73aa (patch)
tree6be94e3fca42b403f2226f66616565fbf3897b72 /src/test/modules/test_regex/sql
parentf40c6969d0eddfc6de786006bd1048961a65a0eb (diff)
downloadpostgresql-4e703d67193df0431c0740044d662d1feade73aa.tar.gz
postgresql-4e703d67193df0431c0740044d662d1feade73aa.zip
Make some minor improvements in the regex code.
Push some hopefully-uncontroversial bits extracted from an upcoming patch series, to remove non-relevant clutter from the main patches. In compact(), return immediately after setting REG_ASSERT error; continuing the loop would just lead to assertion failure below. (Ask me how I know.) In parseqatom(), remove assertion that moresubs() did its job. When moresubs actually did its job, this is redundant with that function's final assert; but when it failed on OOM, this is an assertion crash. We could avoid the crash by adding a NOERR() check before the assertion, but it seems better to subtract code than add it. (Note that there's a NOERR exit a few lines further down, and nothing else between here and there requires moresubs to have succeeded. So we don't really need an extra error exit.) This is a live bug in assert-enabled builds, but given the very low likelihood of OOM in moresub's tiny allocation, I don't think it's worth back-patching. On the other hand, it seems worthwhile to add an assertion that our intended v->subs[subno] target is still null by the time we are ready to insert into it, since there's a recursion in between. In pg_regexec, ensure we fflush any debug output on the way out, and try to make MDEBUG messages more uniform and helpful. (In particular, ensure that all of them are prefixed with the subre's id number, so one can match up entry and exit reports.) Add some test cases in test_regex to improve coverage of lookahead and lookbehind constraints. Adding these now is mainly to establish that this is indeed the existing behavior. Discussion: https://postgr.es/m/1340281.1613018383@sss.pgh.pa.us
Diffstat (limited to 'src/test/modules/test_regex/sql')
-rw-r--r--src/test/modules/test_regex/sql/test_regex.sql13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/test/modules/test_regex/sql/test_regex.sql b/src/test/modules/test_regex/sql/test_regex.sql
index 1a2bfa62357..ae7d6b43e4a 100644
--- a/src/test/modules/test_regex/sql/test_regex.sql
+++ b/src/test/modules/test_regex/sql/test_regex.sql
@@ -1049,6 +1049,10 @@ select * from test_regex('a(?!b)b*', 'a', 'HP');
select * from test_regex('(?=b)b', 'b', 'HP');
-- expectNomatch 23.8 HP (?=b)b a
select * from test_regex('(?=b)b', 'a', 'HP');
+-- expectMatch 23.9 HP ...(?!.) abcde cde
+select * from test_regex('...(?!.)', 'abcde', 'HP');
+-- expectNomatch 23.10 HP ...(?=.) abc
+select * from test_regex('...(?=.)', 'abc', 'HP');
-- Postgres addition: lookbehind constraints
@@ -1068,6 +1072,15 @@ select * from test_regex('a(?<!b)b*', 'a', 'HP');
select * from test_regex('(?<=b)b', 'bb', 'HP');
-- expectNomatch 23.18 HP (?<=b)b b
select * from test_regex('(?<=b)b', 'b', 'HP');
+-- expectMatch 23.19 HP (?<=.).. abcde bc
+select * from test_regex('(?<=.)..', 'abcde', 'HP');
+-- expectMatch 23.20 HP (?<=..)a* aaabb a
+select * from test_regex('(?<=..)a*', 'aaabb', 'HP');
+-- expectMatch 23.21 HP (?<=..)b* aaabb {}
+-- Note: empty match here is correct, it matches after the first 2 characters
+select * from test_regex('(?<=..)b*', 'aaabb', 'HP');
+-- expectMatch 23.22 HP (?<=..)b+ aaabb bb
+select * from test_regex('(?<=..)b+', 'aaabb', 'HP');
-- doing 24 "non-greedy quantifiers"