13 $h{'jkl','mno'} = "JKL\034MNO";
14 $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
45 ok ($#keys == 29, "keys");
46 ok ($#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 ok ($i == 30, "each count");
60 @keys = ('blurfl', keys(%h), 'dyick');
61 ok ($#keys == 31, "added a key");
63 $size = ((split('/',scalar %h))[1]);
65 $newsize = ((split('/',scalar %h))[1]);
66 ok ($newsize == $size * 8, "resize");
68 $size = ((split('/',scalar %h))[1]);
69 ok ($size == $newsize, "same size");
71 $size = ((split('/',scalar %h))[1]);
72 ok ($size == $newsize, "still same size");
75 $size = ((split('/',scalar %h))[1]);
76 ok ($size == 8, "size 8");
81 $total += $key while $key = each %hash;
82 ok ($total == 100, "test scalar each");
84 for (1..3) { @foo = each %hash }
87 $total += $key while $key = each %hash;
88 ok ($total == 100, "test scalar keys resets iterator");
90 for (1..3) { @foo = each %hash }
92 $total += $key while $key = each %hash;
93 ok ($total != 100, "test iterator of each is being maintained");
95 for (1..3) { @foo = each %hash }
98 $total += $key while $key = each %hash;
99 ok ($total == 100, "test values keys resets iterator");
101 $size = (split('/', scalar %hash))[1];
102 keys(%hash) = $size / 2;
103 ok ($size == (split('/', scalar %hash))[1]);
104 keys(%hash) = $size + 100;
105 ok ($size != (split('/', scalar %hash))[1]);
107 ok (keys(%hash) == 10, "keys (%hash)");
109 ok (keys(hash) == 10, "keys (hash)");
112 %h = (a => A, b => B, c=> C, d => D, abc => ABC);
115 while (($key, $value) = each(h)) {
116 if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
122 @tests = (&next_test, &next_test, &next_test);
125 sub DESTROY { print "ok $::tests[1] # DESTROY called\n"; }
127 my $h = { A => bless [], __PACKAGE__ };
128 while (my($k,$v) = each %$h) {
129 print "ok $::tests[0]\n" if $k eq 'A' and ref($v) eq 'Obj';
132 print "ok $::tests[2]\n";
135 # Check for Unicode hash keys.
136 %u = ("\x{12}", "f", "\x{123}", "fo", "\x{1234}", "foo");
137 $u{"\x{12345}"} = "bar";
138 @u{"\x{10FFFD}"} = "zap";
142 ok (length() == 1, "Check length of " . _qq $_);
145 ok (eq_hash(\%u, \%u2), "copied unicode hash keys correctly?");
147 $a = "\xe3\x81\x82"; $A = "\x{3042}";
148 %b = ( $a => "non-utf8");
149 %u = ( $A => "utf8");
151 ok (!exists $b{$A}, "utf8 key in bytes hash");
152 ok (!exists $u{$a}, "bytes key in utf8 hash");
153 print "# $b{$_}\n" for keys %b; # Used to core dump before change #8056.
154 pass ("if we got here change 8056 worked");
155 print "# $u{$_}\n" for keys %u; # Used to core dump before change #8056.
156 pass ("change 8056 is thanks to Inaba Hiroto");
158 # on EBCDIC chars are mapped differently so pick something that needs encoding
160 $d = pack("U*", 0xe3, 0x81, 0xAF);
161 { use bytes; $ol = bytes::length($d) }
162 ok ($ol > 3, "check encoding on EBCDIC");
163 %u = ($d => "downgrade");
165 ok (length == 3, "check length");
166 is ($_, pack("U*", 0xe3, 0x81, 0xAF), "check value");
169 { use bytes; ok (bytes::length($d) == $ol) }
174 my $u0 = pack("U0U", 0x00FF);
175 my $b0 = "\xC3\xBF"; # 0xCB 0xBF is U+00FF in UTF-8
176 my $u1 = pack("U0U", 0x0100);
177 my $b1 = "\xC4\x80"; # 0xC4 0x80 is U+0100 in UTF-8
184 is(scalar keys %u, 4, "four different Unicode keys");
185 is($u{$u0}, 1, "U+00FF -> 1");
186 is($u{$b0}, 2, "U+00C3 U+00BF -> 2");
187 is($u{$u1}, 3, "U+0100 -> 3 ");
188 is($u{$b1}, 4, "U+00C4 U+0080 -> 4");