File: 05_randregex.t

package info (click to toggle)
libstring-random-perl 1%3A0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 168 kB
  • ctags: 14
  • sloc: perl: 347; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (7)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use strict;
use warnings;

use vars qw(@patterns);

BEGIN {
    @patterns=(
        '\d\d\d',
        '\w\w\w',
        '[ABC][abc]',
        '[012][345]',
        '...',
        '[a-z][0-9]',
        '[aw-zX][123]',
        '[a-z]{5}',
        '0{80}',
        '[a-f][nprt]\d{3}',
        '\t\n\r\f\a\e',
        '\S\S\S',
        '\s\s\s',
        '\w{5,10}',
        '\w?',
        '\w+',
        '\w*',
        '',
    );
}

use Test::More tests => (3 * @patterns + 3);

# 1: Make sure we can load the module
BEGIN { use_ok('String::Random'); }

# 2: Make sure we can create a new object
my $foo=new String::Random;
ok(defined($foo), "new()");

# Test regex support
for (@patterns) {
    my $ret=$foo->randregex($_);
    ok($ret =~ /^$_$/, "randregex('$_')")
        or diag "'$_' failed, '$ret' does not match.\n";
}

# Test regex support, but this time pass an array.
my @ret=$foo->randregex(@patterns);
is(@ret, @patterns, "randregex() return")
    or diag "randregex() returned a different array size!";

for (my $n=0;$n<@patterns;$n++) {
    ok(defined($ret[$n]), "defined randregex('$patterns[$n]')");
    ok($ret[$n] =~ /^$patterns[$n]$/, "randregex('$patterns[$n]')")
        or diag "'$patterns[$n]' failed, '$ret[$n]' does not match.\n";
}

# vi: set ai et syntax=perl: