File: assert_in.t

package info (click to toggle)
libcarp-assert-more-perl 1.10-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 164 kB
  • ctags: 26
  • sloc: perl: 762; makefile: 51
file content (73 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl

use warnings;
use strict;

use Test::More tests => 10;

BEGIN { use_ok( 'Carp::Assert::More' ); }

local $@;
$@ = '';

# one element in arrayref
eval {
    assert_in('one', [ 'one' ] );
};
is( $@, '' );

# separate string, two elements
eval {
    my $string = 'B';
    assert_in( $string, [ 'A', 'B' ]  );
};
is( $@, '' );

# separate string and manual arrayref
eval {
    my $string = 'delta';
    my @array = ('alpha','beta','delta');
    assert_in( $string, \@array );
};
is( $@, '' );

# separate string and arrayref
eval {
    my $string = 'tres';
    my $ref = [ 'uno', 'dos', 'tres', 'quatro' ];
    assert_in( $string, $ref  );	
};
is( $@, '' );

# not found fails
eval {
    assert_in( 'F', [ 'A', 'B', 'C', 'D', 'E' ] );
};
like( $@, qr/Assertion.*failed/ );

# undef string fa6yyils
eval {
    assert_in( undef, [ 'fail' ] );
};
like( $@, qr/Assertion.*failed/ );

# empty array fails
eval {
    assert_in( 'empty', [ ] );
};
like( $@, qr/Assertion.*failed/ );

# undef for the arrayref fails
eval {
    my $string = "zippo";
    assert_in( $string, undef );
};
like( $@, qr/Assertion.*failed/ );

# A bad reference should also fail.
eval {
    my $string = "nil";
    my $ref = \$string;
    assert_in( $string, $ref );
};
like( $@, qr/Assertion.*failed/ );