File: 36-large-arrays.t

package info (click to toggle)
libparams-validate-perl 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 996 kB
  • ctags: 879
  • sloc: perl: 2,362; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 891 bytes parent folder | download | duplicates (5)
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
39
40
41
42
use strict;
use warnings;

use Test::Fatal;
use Test::More;

{
    package Foo;

    use Params::Validate qw( validate ARRAYREF );

    sub v1 {
        my %p = validate(
            @_, {
                array => {
                    callbacks => {
                        'checking array contents' => sub {
                            for my $x ( @{ $_[0] } ) {
                                return 0 unless defined $x && !ref $x;
                            }
                            return 1;
                        },
                    }
                }
            }
        );
        return $p{array};
    }
}

{
    for my $size ( 100, 1_000, 100_000 ) {
        my @array = ('x') x $size;
        is_deeply(
            Foo::v1( array => \@array ),
            \@array,
            "validate() handles $size element array correctly"
        );
    }
}

done_testing();