Lots more tests with many permuations of 7, 8 and $lots bit data.
authorNicholas Clark <nick@ccl4.org>
Wed, 19 Sep 2007 21:43:54 +0000 (21:43 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 19 Sep 2007 21:43:54 +0000 (21:43 +0000)
p4raw-id: //depot/perl@31915

ext/XS/APItest/t/hash.t

index 349f054..6faea3f 100644 (file)
@@ -108,6 +108,43 @@ if ($] > 5.009) {
        test_U_hash(\%hash, \%placebo, [f => 9, g => 10, h => 11], $mapping,
                    $name);
     }
+    foreach my $upgrade_o (0, 1) {
+       foreach my $upgrade_n (0, 1) {
+           my (%hash, %placebo);
+           XS::APItest::Hash::bitflip_hash(\%hash);
+           foreach my $new (["7", 65, 67, 80],
+                            ["8", 163, 171, 215],
+                            ["U", 2603, 2604, 2604],
+                           ) {
+               foreach my $code (78, 240, 256, 1336) {
+                   my $key = chr $code;
+                   # This is the UTF-8 byte sequence for the key.
+                   my $key_utf8 = $key;
+                   utf8::encode($key_utf8);
+                   if ($upgrade_o) {
+                       $key .= chr 256;
+                       chop $key;
+                   }
+                   $hash{$key} = $placebo{$key} = $code;
+                   $hash{$key_utf8} = $placebo{$key_utf8} = "$code as UTF-8";
+               }
+               my $name = 'bitflip ' . shift @$new;
+               my @new_kv;
+               foreach my $code (@$new) {
+                   my $key = chr $code;
+                   if ($upgrade_n) {
+                       $key .= chr 256;
+                       chop $key;
+                   }
+                   push @new_kv, $key, $_;
+               }
+
+               $name .= ' upgraded(orig) ' if $upgrade_o;
+               $name .= ' upgraded(new) ' if $upgrade_n;
+               test_U_hash(\%hash, \%placebo, \@new_kv, \&bitflip, $name);
+           }
+       }
+    }
 }
 
 exit;
@@ -123,12 +160,12 @@ sub test_U_hash {
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))),
        "uvar magic called exactly once on store");
 
-    is (keys %$hash, 4);
+    is (keys %$hash, keys %$placebo);
 
     my $victim = shift @hitlist;
     is (delete $hash->{$victim}, delete $placebo->{$victim});
 
-    is (keys %$hash, 3);
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));
 
@@ -136,12 +173,12 @@ sub test_U_hash {
     is (XS::APItest::Hash::delete_ent ($hash, $victim,
                                       XS::APItest::HV_DISABLE_UVAR_XKEY),
        undef, "Deleting a known key with conversion disabled fails (ent)");
-    is (keys %$hash, 3);
+    is (keys %$hash, keys %$placebo);
 
     is (XS::APItest::Hash::delete_ent ($hash, $victim, 0),
        delete $placebo->{$victim},
        "Deleting a known key with conversion enabled works (ent)");
-    is (keys %$hash, 2);
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));
 
@@ -149,33 +186,33 @@ sub test_U_hash {
     is (XS::APItest::Hash::delete ($hash, $victim,
                                   XS::APItest::HV_DISABLE_UVAR_XKEY),
        undef, "Deleting a known key with conversion disabled fails");
-    is (keys %$hash, 2);
+    is (keys %$hash, keys %$placebo);
 
     is (XS::APItest::Hash::delete ($hash, $victim, 0),
        delete $placebo->{$victim},
        "Deleting a known key with conversion enabled works");
-    is(keys %$hash, 1);
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));
 
     my ($k, $v) = splice @$new, 0, 2;
     $hash->{$k} = $v;
     $placebo->{$k} = $v;
-    is(keys %$hash, 2);
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));
 
     ($k, $v) = splice @$new, 0, 2;
     is (XS::APItest::Hash::store_ent($hash, $k, $v), $v, "store_ent");
     $placebo->{$k} = $v;
-    is (keys %$hash, 3);
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));
 
     ($k, $v) = splice @$new, 0, 2;
     is (XS::APItest::Hash::store($hash, $k, $v), $v, "store");
-    is (keys %$hash, 4);
     $placebo->{$k} = $v;
+    is (keys %$hash, keys %$placebo);
     @keys = sort keys %$hash;
     is ("@keys", join(' ', sort($mapping->(keys %$placebo))));