summaryrefslogtreecommitdiff
path: root/t/op
diff options
context:
space:
mode:
Diffstat (limited to 't/op')
-rwxr-xr-xt/op/avhv.t59
1 files changed, 59 insertions, 0 deletions
diff --git a/t/op/avhv.t b/t/op/avhv.t
new file mode 100755
index 0000000000..0390429d2b
--- /dev/null
+++ b/t/op/avhv.t
@@ -0,0 +1,59 @@
+#!./perl
+
+package Tie::StdArray;
+sub TIEARRAY { bless [], $_[0] }
+sub STORE { $_[0]->[$_[1]] = $_[2] }
+sub FETCH { $_[0]->[$_[1]] }
+
+package main;
+
+print "1..4\n";
+
+$sch = {
+ 'abc' => 1,
+ 'def' => 2,
+ 'jkl' => 3,
+};
+
+# basic normal array
+$a = [];
+$a->[0] = $sch;
+
+$a->{'abc'} = 'ABC';
+$a->{'def'} = 'DEF';
+$a->{'jkl'} = 'JKL';
+$a->{'a'} = 'A'; #should extend schema
+
+@keys = keys %$a;
+@values = values %$a;
+
+if ($#keys == 3 && $#values == 3) {print "ok 1\n";} else {print "not ok 1\n";}
+
+$i = 0; # stop -w complaints
+
+while (($key,$value) = each %$a) {
+ if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
+ $key =~ y/a-z/A-Z/;
+ $i++ if $key eq $value;
+ }
+}
+
+if ($i == 4) {print "ok 2\n";} else {print "not ok 2\n";}
+
+# quick check with tied array
+tie @fake, 'Tie::StdArray';
+$a = \@fake;
+$a->[0] = $sch;
+
+$a->{'abc'} = 'ABC';
+if ($a->{'abc'} eq 'ABC') {print "ok 3\n";} else {print "not ok 3\n";}
+
+# quick check with tied array & tied hash
+@INC = ("./lib", "../lib");
+require Tie::Hash;
+tie %fake, Tie::StdHash;
+%fake = %$sch;
+$a->[0] = \%fake;
+
+$a->{'abc'} = 'ABC';
+if ($a->{'abc'} eq 'ABC') {print "ok 4\n";} else {print "not ok 4\n";}