File: 060_each.t

package info (click to toggle)
libsereal-decoder-perl 4.005%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,952 kB
  • sloc: ansic: 8,105; perl: 5,782; sh: 25; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!perl
use strict;
use warnings;
use Test::More;
use File::Spec;
use lib File::Spec->catdir(qw(t lib));
BEGIN {
    lib->import('lib')
        if !-d 't';
}
use Sereal::TestSet qw(:all);
use Sereal::Decoder;

if (have_encoder_and_decoder()) {
    plan tests => 1004;
}
else {
    plan skip_all => 'Did not find right version of encoder';
}

my $e= Sereal::Encoder->new();
my $d= Sereal::Decoder->new();

for ( 1 .. 1000, [ 'a' .. 'z' ], [ 'A' .. 'Z' ], [ 0 .. 100 ], [ 10000 .. 10512 ] ) {
    my %hash;
    if (ref $_) {
        $hash{$_}++ for @$_;
    } else {
        $hash{rand()}++ for 1..26;
    }
    my $undump= $d->decode($e->encode(\%hash));
    my $count= 0;
    while( my ($h, $k)= each %$undump ) {
        $count++;
    }
    is($count, keys %hash, "Got the expected count of keys: [ @{[ sort keys %hash ]} ]"); 
}