summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-08-27 23:29:13 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-08-27 23:37:48 -0700
commit7bc95ae1a56bd0ccfe9db1092344cd2d1566beca (patch)
tree98d78f818036eec595f3ceb97a6d10cad0d11eb9 /t
parentd22667bf3cdadad95b9d176de3bf87d0b0e1286e (diff)
downloadperl-7bc95ae1a56bd0ccfe9db1092344cd2d1566beca.tar.gz
&CORE::substr()
This commit makes &CORE::substr callable through references and via &ampersand syntax. It’s a bit awkward, as we need a substr op that is flagged as hav- ing 4 arguments *and* possibly returning an lvalue. The code in op_lvalue_flags wasn’t really set up for that, so I needed to flag the op with OPpMAYBE_LVSUB in coresub_op before it gets passed to op_lvalue_flags. It turned out that only that was necessary, as op_lvalue_flags does an op_private == 4 check (rather than (op_private & 7) == 4 or some such) when checking for the 4-arg case and croak- ing. When the op arrives in op_lvalue_flags, it’s already flagged OPpMAYBE_LVSUB|4 which != 4. pp_substr is also modified to check for nulls and, if necessary, adjust its count of how many arguments were actually passed.)
Diffstat (limited to 't')
-rw-r--r--t/op/coreamp.t10
1 files changed, 10 insertions, 0 deletions
diff --git a/t/op/coreamp.t b/t/op/coreamp.t
index b9b946fbe0..3347756675 100644
--- a/t/op/coreamp.t
+++ b/t/op/coreamp.t
@@ -670,6 +670,16 @@ $tests ++;
&CORE::srand;
pass '&srand with no args does not crash';
+test_proto 'substr';
+$tests += 5;
+$_ = "abc";
+is &mysubstr($_, 1, 1, "d"), 'b', '4-arg &substr';
+is $_, 'adc', 'what 4-arg &substr does';
+is &mysubstr("abc", 1, 1), 'b', '3-arg &substr';
+is &mysubstr("abc", 1), 'bc', '2-arg &substr';
+&mysubstr($_, 1) = 'long';
+is $_, 'along', 'lvalue &substr';
+
test_proto 'symlink';
test_proto 'syscall';
test_proto 'sysread';