13 $h{'jkl','mno'} = "JKL\034MNO";
14 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
45 is ($#keys, 29, "keys");
46 is ($#values, 29, "values");
48 $i = 0; # stop -w complaints
50 while (($key,$value) = each(%h)) {
51 if ($key eq $keys[$i] && $value eq $values[$i]
52 && (('a' lt 'A' && $key lt $value) || $key gt $value)) {
54 $i++ if $key eq $value;
58 is ($i, 30, "each count");
60 @keys = ('blurfl', keys(%h), 'dyick');
61 is ($#keys, 31, "added a key");
63 $size = ((split('/',scalar %h))[1]);
65 $newsize = ((split('/',scalar %h))[1]);
66 is ($newsize, $size * 8, "resize");
68 $size = ((split('/',scalar %h))[1]);
69 is ($size, $newsize, "same size");
71 $size = ((split('/',scalar %h))[1]);
72 is ($size, $newsize, "still same size");
75 $size = ((split('/',scalar %h))[1]);
76 is ($size, 8, "size 8");
81 $total += $key while $key = each %hash;
82 is ($total, 100, "test scalar each");
84 for (1..3) { @foo = each %hash }
87 $total += $key while $key = each %hash;
88 is ($total, 100, "test scalar keys resets iterator");
90 for (1..3) { @foo = each %hash }
92 $total += $key while $key = each %hash;
93 isnt ($total, 100, "test iterator of each is being maintained");
95 for (1..3) { @foo = each %hash }
98 $total += $key while $key = each %hash;
99 is ($total, 100, "test values keys resets iterator");
101 $size = (split('/', scalar %hash))[1];
102 keys(%hash) = $size / 2;
103 is ($size, (split('/', scalar %hash))[1]);
104 keys(%hash) = $size + 100;
105 isnt ($size, (split('/', scalar %hash))[1]);
107 is (keys(%hash), 10, "keys (%hash)");
110 no warnings 'deprecated';
111 is (keys(hash), 10, "keys (hash)");
115 %h = (a => A, b => B, c=> C, d => D, abc => ABC);
117 no warnings 'deprecated';
120 while (($key, $value) = each(h)) {
121 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
128 @tests = (&next_test, &next_test, &next_test);
131 sub DESTROY { print "ok $::tests[1] # DESTROY called\n"; }
133 my $h = { A => bless [], __PACKAGE__ };
134 while (my($k,$v) = each %$h) {
135 print "ok $::tests[0]\n" if $k eq 'A' and ref($v) eq 'Obj';
138 print "ok $::tests[2]\n";
141 # Check for Unicode hash keys.
142 %u = ("\x{12}", "f", "\x{123}", "fo", "\x{1234}", "foo");
143 $u{"\x{12345}"} = "bar";
144 @u{"\x{10FFFD}"} = "zap";
148 is (length(), 1, "Check length of " . _qq $_);
151 ok (eq_hash(\%u, \%u2), "copied unicode hash keys correctly?");
153 $a = "\xe3\x81\x82"; $A = "\x{3042}";
154 %b = ( $a => "non-utf8");
155 %u = ( $A => "utf8");
157 is (exists $b{$A}, '', "utf8 key in bytes hash");
158 is (exists $u{$a}, '', "bytes key in utf8 hash");
159 print "# $b{$_}\n" for keys %b; # Used to core dump before change #8056.
160 pass ("if we got here change 8056 worked");
161 print "# $u{$_}\n" for keys %u; # Used to core dump before change #8056.
162 pass ("change 8056 is thanks to Inaba Hiroto");
164 # on EBCDIC chars are mapped differently so pick something that needs encoding
166 $d = pack("U*", 0xe3, 0x81, 0xAF);
167 { use bytes; $ol = bytes::length($d) }
168 cmp_ok ($ol, '>', 3, "check encoding on EBCDIC");
169 %u = ($d => "downgrade");
171 is (length, 3, "check length");
172 is ($_, pack("U*", 0xe3, 0x81, 0xAF), "check value");
175 { use bytes; is (bytes::length($d), $ol) }
180 my $u0 = pack("U0U", 0x00FF);
181 my $b0 = "\xC3\xBF"; # 0xCB 0xBF is U+00FF in UTF-8
182 my $u1 = pack("U0U", 0x0100);
183 my $b1 = "\xC4\x80"; # 0xC4 0x80 is U+0100 in UTF-8
190 is(scalar keys %u, 4, "four different Unicode keys");
191 is($u{$u0}, 1, "U+00FF -> 1");
192 is($u{$b0}, 2, "U+00C3 U+00BF -> 2");
193 is($u{$u1}, 3, "U+0100 -> 3 ");
194 is($u{$b1}, 4, "U+00C4 U+0080 -> 4");
197 # test for syntax errors
198 for my $k (qw(each keys values)) {
200 like($@, qr/^Not enough arguments for $k/, "$k demands argument");
207 my ($k1,$v1)=each(%foo);
210 my ($k2,$v2)=each(%foo);
212 while (each(%foo)) {$rest++};
213 is($yes,1,"if(%foo) was true");
214 isnt($k1,$k2,"if(%foo) didnt mess with each (key)");
215 isnt($v1,$v2,"if(%foo) didnt mess with each (value)");
216 is($rest,3,"Got the expect number of keys");
218 like($hsv,'/',"Got bucket stats from %foo in scalar assignment context");
224 my ($k1,$v1)=each(%foo);
227 my ($k2,$v2)=each(%foo);
229 while (each(%foo)) {$rest++};
230 is($yes,1,"if(%foo) was true");
231 isnt($k1,$k2,"if(%foo) didnt mess with each (key)");
232 isnt($v1,$v2,"if(%foo) didnt mess with each (value)");
233 is($rest,3,"Got the expect number of keys");
235 like($hsv,'/',"Got bucket stats from %foo in scalar assignment context");