This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Precomputing the hash value for a string representable in bytes, but passed in
[perl5.git] / ext / XS / APItest / t / hash.t
index 1ef99ed..47d4437 100644 (file)
@@ -150,6 +150,27 @@ if ($] > 5.009) {
     }
 }
 
     }
 }
 
+{
+    my $as_utf8 = "\241" . chr 256;
+    chop $as_utf8;
+    my $as_bytes = "\243";
+    foreach my $key ('N', $as_bytes, $as_utf8, "\x{2623}") {
+       my $ord = ord $key;
+       foreach my $hash_pv (0, 1) {
+           my %hash;
+           is (XS::APItest::Hash::common({hv => \%hash, keypv => $key,
+                                          val => $ord, hash_pv => $hash_pv,
+                                          action =>
+                                          XS::APItest::HV_FETCH_ISSTORE}),
+               $ord, "store $ord \$hash_pv = $hash_pv");
+           is_deeply ([each %hash], [$key, $ord], "First key read is good");
+           is_deeply ([each %hash], [], "No second key good");
+
+           is ($hash{$key}, $ord, "Direct hash read finds $ord");
+       }
+    }
+}
+
 exit;
 
 ################################   The End   ################################
 exit;
 
 ################################   The End   ################################