diff options
author | Joshua Pritikin <joshua.pritikin@db.com> | 1997-11-15 14:18:30 -0500 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-11-18 17:26:09 +0000 |
commit | 5d5aaa5e70a8a8ab4803cdb506e2096b6e190e80 (patch) | |
tree | fed0a7a563aeb29c7ea8ca58452d4432be9b0c67 /t/op | |
parent | 3487771ddbb6a6913db5c4e74398b9812ab6476b (diff) | |
download | perl-5d5aaa5e70a8a8ab4803cdb506e2096b6e190e80.tar.gz |
Separate avhv_foo() key handling into avhv_keys(). Slightly tweaked
version of patch:
Subject: tie fake hash patch for 5.004_54
p4raw-id: //depot/perl@266
Diffstat (limited to 't/op')
-rwxr-xr-x | t/op/avhv.t | 59 |
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";} |