summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2010-08-18 23:48:16 -0600
committerFlorian Ragwitz <rafl@debian.org>2010-09-20 08:13:30 +0200
commitfb85c0447bf1d343a9b4d4d7075184aeb4c9ae46 (patch)
tree47c8406e939af312e69568c7a9ced9ec7d3529ed /t
parent5c3fa2e7f75bb4370f758b363cec53992c7fd20a (diff)
downloadperl-fb85c0447bf1d343a9b4d4d7075184aeb4c9ae46.tar.gz
Add (?^...) regex construct
This adds (?^...) to signify to use the default regex modifiers for the cluster or embedded pattern-match modifier change. The major purpose of this is to simplify regex stringification, so that "^" is output in place of "-xism". As a result, the stringification will not change in the future when new regex modifiers are added, so tests, etc. that rely on a particular stringification will have to change now, but never again. Code that needs to work properly with both old- and new-style regexes can use something like the following: # Accept both old and new-style stringification my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? '^' : '-xism'; This construct is Ben Morrow's idea.
Diffstat (limited to 't')
-rw-r--r--t/comp/parser.t2
-rw-r--r--t/lib/warnings/regcomp5
-rw-r--r--t/re/pat.t10
-rw-r--r--t/re/pat_re_eval.t4
-rw-r--r--t/re/re.t5
-rw-r--r--t/run/fresh_perl.t2
6 files changed, 16 insertions, 12 deletions
diff --git a/t/comp/parser.t b/t/comp/parser.t
index 8fd94530cb..5c64d11fb2 100644
--- a/t/comp/parser.t
+++ b/t/comp/parser.t
@@ -125,7 +125,7 @@ is( $@, '', 'PL_lex_brackstack' );
is("${a}[", "A[", "interpolation, qq//");
my @b=("B");
is("@{b}{", "B{", "interpolation, qq//");
- is(qr/${a}{/, '(?-xism:A{)', "interpolation, qr//");
+ is(qr/${a}{/, '(?^:A{)', "interpolation, qr//");
my $c = "A{";
$c =~ /${a}{/;
is($&, 'A{', "interpolation, m//");
diff --git a/t/lib/warnings/regcomp b/t/lib/warnings/regcomp
index 98280f61f4..2842882371 100644
--- a/t/lib/warnings/regcomp
+++ b/t/lib/warnings/regcomp
@@ -250,3 +250,8 @@ $a = qr/[\8\9]/;
EXPECT
Unrecognized escape \8 in character class passed through in regex; marked by <-- HERE in m/[\8 <-- HERE \9]/ at - line 3.
Unrecognized escape \9 in character class passed through in regex; marked by <-- HERE in m/[\8\9 <-- HERE ]/ at - line 3.
+########
+# regcomp.c [Perl_re_compile]
+$a = qr/(?^-i:foo)/;
+EXPECT
+Sequence (?^-...) not recognized in regex; marked by <-- HERE in m/(?^- <-- HERE i:foo)/ at - line 2.
diff --git a/t/re/pat.t b/t/re/pat.t
index ba0efcdc98..3bc7f5d372 100644
--- a/t/re/pat.t
+++ b/t/re/pat.t
@@ -499,12 +499,12 @@ sub run_tests {
}
{
- iseq qr/\b\v$/i, '(?i-xsm:\b\v$)', 'qr/\b\v$/i';
- iseq qr/\b\v$/s, '(?s-xim:\b\v$)', 'qr/\b\v$/s';
- iseq qr/\b\v$/m, '(?m-xis:\b\v$)', 'qr/\b\v$/m';
- iseq qr/\b\v$/x, '(?x-ism:\b\v$)', 'qr/\b\v$/x';
+ iseq qr/\b\v$/i, '(?^i:\b\v$)', 'qr/\b\v$/i';
+ iseq qr/\b\v$/s, '(?^s:\b\v$)', 'qr/\b\v$/s';
+ iseq qr/\b\v$/m, '(?^m:\b\v$)', 'qr/\b\v$/m';
+ iseq qr/\b\v$/x, '(?^x:\b\v$)', 'qr/\b\v$/x';
iseq qr/\b\v$/xism, '(?msix:\b\v$)', 'qr/\b\v$/xism';
- iseq qr/\b\v$/, '(?-xism:\b\v$)', 'qr/\b\v$/';
+ iseq qr/\b\v$/, '(?^:\b\v$)', 'qr/\b\v$/';
}
diff --git a/t/re/pat_re_eval.t b/t/re/pat_re_eval.t
index fab828d17d..6fcbb9360b 100644
--- a/t/re/pat_re_eval.t
+++ b/t/re/pat_re_eval.t
@@ -77,7 +77,7 @@ sub run_tests {
{
our $a = bless qr /foo/ => 'Foo';
ok 'goodfood' =~ $a, "Reblessed qr // matches";
- iseq $a, '(?-xism:foo)', "Reblessed qr // stringifies";
+ iseq $a, '(?^:foo)', "Reblessed qr // stringifies";
my $x = "\x{3fe}";
my $z = my $y = "\317\276"; # Byte representation of $x
$a = qr /$x/;
@@ -88,7 +88,7 @@ sub run_tests {
"Postponed interpolation of qr // preserves UTF-8";
{
local $BugId = '17776';
- iseq length qr /##/x, 12, "## in qr // doesn't corrupt memory";
+ iseq length qr /##/x, 9, "## in qr // doesn't corrupt memory";
}
{
use re 'eval';
diff --git a/t/re/re.t b/t/re/re.t
index 249c6ddf22..10e2ee2b64 100644
--- a/t/re/re.t
+++ b/t/re/re.t
@@ -21,12 +21,11 @@ use re qw(is_regexp regexp_pattern
is((regexp_pattern($qr))[0],'foo','regexp_pattern[0] (ref)');
is((regexp_pattern($qr))[1],'ip','regexp_pattern[1] (ref)');
- is(regexp_pattern($qr),'(?pi-xsm:foo)','scalar regexp_pattern (ref)');
+ is(regexp_pattern($qr),'(?^pi:foo)','scalar regexp_pattern (ref)');
is((regexp_pattern($rx))[0],'foo','regexp_pattern[0] (bare REGEXP)');
is((regexp_pattern($rx))[1],'ip','regexp_pattern[1] (bare REGEXP)');
- is(regexp_pattern($rx),'(?pi-xsm:foo)',
- 'scalar regexp_pattern (bare REGEXP)');
+ is(regexp_pattern($rx),'(?^pi:foo)', 'scalar regexp_pattern (bare REGEXP)');
ok(!regexp_pattern(''),'!regexp_pattern("")');
}
diff --git a/t/run/fresh_perl.t b/t/run/fresh_perl.t
index 2019d9b520..3666f0922e 100644
--- a/t/run/fresh_perl.t
+++ b/t/run/fresh_perl.t
@@ -605,7 +605,7 @@ EXPECT
# reversed again as a result of [perl #17763]
die qr(x)
EXPECT
-(?-xism:x)
+(?^:x)
########
# 20001210.003 mjd@plover.com
format REMITOUT_TOP =