Add new tests for bug #32840 provided by David Landgren,
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 20 Apr 2006 20:22:23 +0000 (20:22 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 20 Apr 2006 20:22:23 +0000 (20:22 +0000)
as a new file rxcode.t (they mostly test $^R for now)

p4raw-id: //depot/perl@27922

MANIFEST
t/op/rxcode.t [new file with mode: 0644]

index 13f8b29..0e71a39 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3421,6 +3421,7 @@ t/op/regmesg.t                    See if one can get regular expression errors
 t/op/repeat.t                  See if x operator works
 t/op/re_tests                  Regular expressions for regexp.t
 t/op/reverse.t                 See if reverse operator works
+t/op/rxcode.t                  See if /(?{ code })/ works
 t/op/runlevel.t                        See if die() works from perl_call_*()
 t/op/sleep.t                   See if sleep works
 t/op/smartmatch.t              See if the ~~ operator works
diff --git a/t/op/rxcode.t b/t/op/rxcode.t
new file mode 100644 (file)
index 0000000..18b1b3e
--- /dev/null
@@ -0,0 +1,74 @@
+use Test::More tests => 34;
+
+$^R = undef;
+like( 'a',  qr/^a(?{1})(?:b(?{2}))?/, 'a =~ ab?' );
+cmp_ok( $^R, '==', 1, '..$^R after a =~ ab?' );
+
+$^R = undef;
+unlike( 'abc', qr/^a(?{3})(?:b(?{4}))$/, 'abc !~ a(?:b)$' );
+ok( !defined $^R, '..$^R after abc !~ a(?:b)$' );
+
+$^R = undef;
+like( 'ab', qr/^a(?{5})b(?{6})/, 'ab =~ ab' );
+cmp_ok( $^R, '==', 6, '..$^R after ab =~ ab' );
+
+$^R = undef;
+like( 'ab', qr/^a(?{7})(?:b(?{8}))?/, 'ab =~ ab?' );
+
+TODO: {
+    local $TODO = '#32840: $^R value lost in (?:...)? constructs';
+    cmp_ok( $^R, '==', 8, '..$^R after ab =~ ab?' );
+}
+
+$^R = undef;
+like( 'ab', qr/^a(?{9})b?(?{10})/, 'ab =~ ab? (2)' );
+cmp_ok( $^R, '==', 10, '..$^R after ab =~ ab? (2)' );
+
+$^R = undef;
+like( 'ab', qr/^(a(?{11})(?:b(?{12})))?/, 'ab =~ (ab)? (3)' );
+TODO: {
+    local $TODO = '#32840: $^R value lost in (?:...)? constructs (2)';
+    cmp_ok( $^R, '==', 12, '..$^R after ab =~ ab? (3)' );
+}
+
+$^R = undef;
+unlike( 'ac', qr/^a(?{13})b(?{14})/, 'ac !~ ab' );
+ok( !defined $^R, '..$^R after ac !~ ab' );
+
+$^R = undef;
+like( 'ac', qr/^a(?{15})(?:b(?{16}))?/, 'ac =~ ab?' );
+cmp_ok( $^R, '==', 15, '..$^R after ac =~ ab?' );
+
+my @ar;
+like( 'ab', qr/^a(?{push @ar,101})(?:b(?{push @ar,102}))?/, 'ab =~ ab? with code push' );
+cmp_ok( scalar(@ar), '==', 2, '..@ar pushed' );
+cmp_ok( $ar[0], '==', 101, '..first element pushed' );
+cmp_ok( $ar[1], '==', 102, '..second element pushed' );
+
+$^R = undef;
+unlike( 'a', qr/^a(?{103})b(?{104})/, 'a !~ ab with code push' );
+ok( !defined $^R, '..$^R after a !~ ab with code push' );
+
+@ar = ();
+unlike( 'a', qr/^a(?{push @ar,105})b(?{push @ar,106})/, 'a !~ ab (push)' );
+cmp_ok( scalar(@ar), '==', 0, '..nothing pushed' );
+
+@ar = ();
+unlike( 'abc', qr/^a(?{push @ar,107})b(?{push @ar,108})$/, 'abc !~ ab$ (push)' );
+cmp_ok( scalar(@ar), '==', 0, '..still nothing pushed' );
+
+use vars '@var';
+
+like( 'ab', qr/^a(?{push @var,109})(?:b(?{push @var,110}))?/, 'ab =~ ab? push to package var' );
+cmp_ok( scalar(@var), '==', 2, '..@var pushed' );
+cmp_ok( $var[0], '==', 109, '..first element pushed (package)' );
+cmp_ok( $var[1], '==', 110, '..second element pushed (package)' );
+
+@var = ();
+unlike( 'a', qr/^a(?{push @var,111})b(?{push @var,112})/, 'a !~ ab (push package var)' );
+cmp_ok( scalar(@var), '==', 0, '..nothing pushed (package)' );
+
+@var = ();
+unlike( 'abc', qr/^a(?{push @var,113})b(?{push @var,114})$/, 'abc !~ ab$ (push package var)' );
+cmp_ok( scalar(@var), '==', 0, '..still nothing pushed (package)' );
+