$^P |= 0x100;
}
-use Hash::Util;
no warnings 'experimental::smartmatch';
sub lis($$;$) {
lis [sort &mykeys({1..4})], [1,3], '&mykeys(\%hash) in list cx';
is &mykeys([ 1..4 ]), 4, '&mykeys(\@array) in scalar cx';
lis [&mykeys([ 1..4 ])], [0..3], '&mykeys(\@array) in list cx';
-{
+
+SKIP: {
+ skip "no Hash::Util on miniperl", 2, if is_miniperl;
+ require Hash::Util;
+ sub Hash::Util::bucket_ratio (\%);
+
my %h = 1..2;
&mykeys(\%h) = 1024;
like Hash::Util::bucket_ratio(%h), qr|/1024\z|, '&mykeys = changed number of buckets allocated';
@INC = '../lib';
require './test.pl';
}
-use Hash::Util;
plan tests => 59;
@keys = ('blurfl', keys(%h), 'dyick');
is ($#keys, 31, "added a key");
-$size = Hash::Util::num_buckets(%h);
-keys %h = $size * 5;
-$newsize = Hash::Util::num_buckets(%h);
-is ($newsize, $size * 8, "resize");
-keys %h = 1;
-$size = Hash::Util::num_buckets(%h);
-is ($size, $newsize, "same size");
-%h = (1,1);
-$size = Hash::Util::num_buckets(%h);
-is ($size, $newsize, "still same size");
-undef %h;
-%h = (1,1);
-$size = Hash::Util::num_buckets(%h);
-is ($size, 8, "size 8");
+SKIP: {
+ skip "no Hash::Util on miniperl", 4, if is_miniperl;
+ require Hash::Util;
+ sub Hash::Util::num_buckets (\%);
+
+ $size = Hash::Util::num_buckets(%h);
+ keys %h = $size * 5;
+ $newsize = Hash::Util::num_buckets(%h);
+ is ($newsize, $size * 8, "resize");
+ keys %h = 1;
+ $size = Hash::Util::num_buckets(%h);
+ is ($size, $newsize, "same size");
+ %h = (1,1);
+ $size = Hash::Util::num_buckets(%h);
+ is ($size, $newsize, "still same size");
+ undef %h;
+ %h = (1,1);
+ $size = Hash::Util::num_buckets(%h);
+ is ($size, 8, "size 8");
+}
# test scalar each
%hash = 1..20;
$total += $key while $key = each %hash;
is ($total, 100, "test values keys resets iterator");
-$size = Hash::Util::num_buckets(%hash);
-keys(%hash) = $size / 2;
-is ($size, Hash::Util::num_buckets(%hash),
- "assign to keys does not shrink hash bucket array");
-keys(%hash) = $size + 100;
-isnt ($size, Hash::Util::num_buckets(%hash),
- "assignment to keys of a number not large enough does not change size");
-
-is (keys(%hash), 10, "keys (%hash)");
+SKIP: {
+ skip "no Hash::Util on miniperl", 3, if is_miniperl;
+ require Hash::Util;
+ sub Hash::Util::num_buckets (\%);
+
+ $size = Hash::Util::num_buckets(%hash);
+ keys(%hash) = $size / 2;
+ is ($size, Hash::Util::num_buckets(%hash),
+ "assign to keys does not shrink hash bucket array");
+ keys(%hash) = $size + 100;
+ isnt ($size, Hash::Util::num_buckets(%hash),
+ "assignment to keys of a number not large enough does not change size");
+ is (keys(%hash), 10, "keys (%hash)");
+}
@tests = (&next_test, &next_test, &next_test);
{
}
use strict;
-use Hash::Util;
+
# This will crash perl if it fails
use constant PVBM => 'foo';
is($scalar, $count, "$desc scalar() should be the same as 0+keys() as of perl 5.25");
+ require Hash::Util;
+ sub Hash::Util::bucket_ratio (\%);
+
# back compat tests, via Hash::Util::bucket_ratio();
my $ratio = Hash::Util::bucket_ratio(%$h);
my $expect = qr!\A(\d+)/(\d+)\z!;
is(scalar %$h1, scalar %$h, "scalar keys is identical on copy and original");
}
-torture_hash('a .. zz', 'a' .. 'zz');
-torture_hash('0 .. 9', 0 .. 9);
-torture_hash("'Perl'", 'Rules');
+if (is_miniperl) {
+ print "# skipping torture_hash tests on miniperl because no Hash::Util\n";
+} else {
+ torture_hash('a .. zz', 'a' .. 'zz');
+ torture_hash('0 .. 9', 0 .. 9);
+ torture_hash("'Perl'", 'Rules');
+}
{
my %h = qw(a x b y c z);
require './test.pl';
}
plan tests=>211;
-use Hash::Util;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
}
is("@p", "1 8");
-sub keeze : lvalue { keys %__ }
-%__ = ("a","b");
-keeze = 64;
-is Hash::Util::bucket_ratio(%__), '1/64', 'keys assignment through lvalue sub';
-eval { (keeze) = 64 };
-like $@, qr/^Can't modify keys in list assignment at /,
- 'list assignment to keys through lv sub is forbidden';
-sub akeeze : lvalue { keys @_ }
-eval { (akeeze) = 64 };
-like $@, qr/^Can't modify keys on array in list assignment at /,
- 'list assignment to keys @_ through lv sub is forbidden';
+SKIP: {
+ skip "no Hash::Util on miniperl", 3, if is_miniperl;
+ require Hash::Util;
+ sub Hash::Util::bucket_ratio (\%);
+
+ sub keeze : lvalue { keys %__ }
+ %__ = ("a","b");
+ keeze = 64;
+ is Hash::Util::bucket_ratio(%__), '1/64', 'keys assignment through lvalue sub';
+ eval { (keeze) = 64 };
+ like $@, qr/^Can't modify keys in list assignment at /,
+ 'list assignment to keys through lv sub is forbidden';
+ sub akeeze : lvalue { keys @_ }
+ eval { (akeeze) = 64 };
+ like $@, qr/^Can't modify keys on array in list assignment at /,
+ 'list assignment to keys @_ through lv sub is forbidden';
+}
# Bug 20001223.002 (#5005): split thought that the list had only one element
@ary = qw(4 5 6);