summaryrefslogtreecommitdiff
path: root/ext/arybase/t/aelem.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-10-21 05:58:40 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-10-21 22:12:59 -0700
commitb82b06b8ca329f89b70366e25afb8e2be30b446e (patch)
tree2048b9c510b101230175661356eae7ca5d1f4ba6 /ext/arybase/t/aelem.t
parent0be9b861b326969b378910bfcdea3f19d0d42992 (diff)
downloadperl-b82b06b8ca329f89b70366e25afb8e2be30b446e.tar.gz
Reimplement $[ as a module
This commit reimplements $[ using PL_check hooks, custom pp func- tions and ties. Outside of its compile-time use, $[ is now parsed as a simple varia- ble, so function calls like foo($[) are permitted, which was not the case with the former implementation removed by e1dccc0. I consider that a bug fix. The ‘That use of $[ is unsupported’ errors are out of necessity deferred to run-time and implemented by a tied $[. Indices between 0 and the array base are now treated consistently, as are indices between a negative array base and zero. That, too, is a bug fix.
Diffstat (limited to 'ext/arybase/t/aelem.t')
-rw-r--r--ext/arybase/t/aelem.t56
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/arybase/t/aelem.t b/ext/arybase/t/aelem.t
new file mode 100644
index 0000000000..d6b8c38149
--- /dev/null
+++ b/ext/arybase/t/aelem.t
@@ -0,0 +1,56 @@
+use warnings;
+use strict;
+
+use Test::More tests => 33;
+
+our @t = qw(a b c d e f);
+our $r = \@t;
+our($i3, $i4, $i8, $i9) = (3, 4, 8, 9);
+our @i4 = (3, 3, 3, 3);
+
+$[ = 3;
+
+is $t[3], "a";
+is $t[4], "b";
+is $t[8], "f";
+is $t[9], undef;
+is_deeply [ scalar $t[4] ], [ "b" ];
+is_deeply [ $t[4] ], [ "b" ];
+
+is $t[2], 'f';
+is $t[-1], 'f';
+is $t[1], 'e';
+is $t[-2], 'e';
+
+{
+ $[ = -3;
+ is $t[-3], 'a';
+}
+
+is $r->[3], "a";
+is $r->[4], "b";
+is $r->[8], "f";
+is $r->[9], undef;
+is_deeply [ scalar $r->[4] ], [ "b" ];
+is_deeply [ $r->[4] ], [ "b" ];
+
+is $t[$i3], "a";
+is $t[$i4], "b";
+is $t[$i8], "f";
+is $t[$i9], undef;
+is_deeply [ scalar $t[$i4] ], [ "b" ];
+is_deeply [ $t[$i4] ], [ "b" ];
+is_deeply [ scalar $t[@i4] ], [ "b" ];
+is_deeply [ $t[@i4] ], [ "b" ];
+
+is $r->[$i3], "a";
+is $r->[$i4], "b";
+is $r->[$i8], "f";
+is $r->[$i9], undef;
+is_deeply [ scalar $r->[$i4] ], [ "b" ];
+is_deeply [ $r->[$i4] ], [ "b" ];
+is_deeply [ scalar $r->[@i4] ], [ "b" ];
+is_deeply [ $r->[@i4] ], [ "b" ];
+
+
+1;