13 # Two hashes one will all keys 8-bit possible (initially), other
14 # with a utf8 requiring key from the outset.
16 my %hash8 = ( "\xff" => 0xff,
19 my %hashu = ( "\xff" => 0xff,
24 # Check that we can find the 8-bit things by various litterals
25 is($hash8{"\x{00ff}"},0xFF);
26 is($hash8{"\x{007f}"},0x7F);
27 is($hash8{"\xff"},0xFF);
28 is($hash8{"\x7f"},0x7F);
29 is($hashu{"\x{00ff}"},0xFF);
30 is($hashu{"\x{007f}"},0x7F);
31 is($hashu{"\xff"},0xFF);
32 is($hashu{"\x7f"},0x7F);
34 # Now try same thing with variables forced into various forms.
35 foreach my $a ("\x7f","\xff")
38 is($hash8{$a},ord($a));
39 is($hashu{$a},ord($a));
41 is($hash8{$a},ord($a));
42 is($hashu{$a},ord($a));
45 is($hash8{$b},ord($b));
46 is($hashu{$b},ord($b));
49 # Check we have not got an spurious extra keys
50 is(join('',sort { ord $a <=> ord $b } keys %hash8),"\x7f\xff");
51 is(join('',sort { ord $a <=> ord $b } keys %hashu),"\x7f\xff\x{1ff}");
53 # Now add a utf8 key to the 8-bit hash
54 $hash8{chr(0x1ff)} = 0x1ff;
56 # Check we have not got an spurious extra keys
57 is(join('',sort { ord $a <=> ord $b } keys %hash8),"\x7f\xff\x{1ff}");
59 foreach my $a ("\x7f","\xff","\x{1ff}")
62 is($hash8{$a},ord($a));
65 is($hash8{$b},ord($b));
68 # and remove utf8 from the other hash
69 is(delete $hashu{chr(0x1ff)},0x1ff);
70 is(join('',sort keys %hashu),"\x7f\xff");
72 foreach my $a ("\x7f","\xff")
75 is($hashu{$a},ord($a));
77 is($hashu{$a},ord($a));
80 is($hashu{$b},ord($b));
86 print "# Unicode hash keys and \\w\n";
87 # This is not really a regex test but regexes bring
88 # out the issue nicely.
90 my $u3 = "f\x{df}\x{100}";
91 my $u2 = substr($u3,0,2);
92 my $u1 = substr($u2,0,1);
93 my $u0 = chr (0xdf)x4; # Make this 4 chars so that all lengths are distinct.
95 my @u = ($u0, $u1, $u2, $u3);
98 my %u = (map {( $_, $_)} @u);
100 $keys .= ($keys == 1) ? " key" : " keys";
104 my $r = 0 + $u{$_} =~ /^\w+$/;
105 is ($l, $r, "\\w on keys with $keys, key of length " . length $_);
111 # Want to do this direct, rather than copying to a temporary variable
112 # The first time each will return key and value at the start of the hash.
113 # each will return () after we've done the last pair. $more won't get
114 # set then, and the do will exit.
118 my $r = 0 + $u{$_} =~ /^\w+$/;
119 is ($l, $r, "\\w on each, with $keys, key of length " . length $_);
125 my $r = 0 + $u{$_} =~ /^\w+$/;
126 is ($l, $r, "\\w on hash with $keys, key of length " . length $_);
134 my $utf8_sz = my $bytes_sz = "\x{df}";
138 my (%bytes_first, %utf8_first);
140 $bytes_first{$bytes_sz} = $bytes_sz;
142 for (keys %bytes_first) {
144 my $r = 0 + $bytes_first{$_} =~ /^\w+$/;
145 is ($l, $r, "\\w on each, bytes");
148 $bytes_first{$utf8_sz} = $utf8_sz;
150 for (keys %bytes_first) {
152 my $r = 0 + $bytes_first{$_} =~ /^\w+$/;
153 is ($l, $r, "\\w on each, bytes now utf8");
156 $utf8_first{$utf8_sz} = $utf8_sz;
158 for (keys %utf8_first) {
160 my $r = 0 + $utf8_first{$_} =~ /^\w+$/;
161 is ($l, $r, "\\w on each, utf8");
164 $utf8_first{$bytes_sz} = $bytes_sz;
166 for (keys %utf8_first) {
168 my $r = 0 + $utf8_first{$_} =~ /^\w+$/;
169 is ($l, $r, "\\w on each, utf8 now bytes");