1#!/usr/bin/perl 2 3use warnings; 4use strict; 5 6use Test::More tests => 12; 7 8use Carp::Assert::More; 9 10local $@; 11$@ = ''; 12 13# one element in arrayref 14eval { 15 assert_in('one', [ 'one' ] ); 16}; 17is( $@, '' ); 18 19# separate string, two elements 20eval { 21 my $string = 'B'; 22 assert_in( $string, [ 'A', 'B' ] ); 23}; 24is( $@, '' ); 25 26# separate string and manual arrayref 27eval { 28 my $string = 'delta'; 29 my @array = ('alpha','beta','delta'); 30 assert_in( $string, \@array ); 31}; 32is( $@, '' ); 33 34# separate string and arrayref 35eval { 36 my $string = 'tres'; 37 my $ref = [ 'uno', 'dos', 'tres', 'quatro' ]; 38 assert_in( $string, $ref ); 39}; 40is( $@, '' ); 41 42# not found fails 43eval { 44 assert_in( 'F', [ 'A', 'B', 'C', 'D', 'E' ] ); 45}; 46like( $@, qr/Assertion.*failed/ ); 47 48# undef in the list is OK 49eval { 50 assert_in( 'C', [ 'A', 'B', 'C', undef ] ); 51}; 52is( $@, '' ); 53 54# undef is an OK value to match against the list. 55eval { 56 assert_in( undef, [ 'A', 'B', 'C', undef ] ); 57}; 58is( $@, '' ); 59 60# refs in the list fails 61eval { 62 assert_in( 'C', [ 'A', 'B', 'C', {} ] ); 63}; 64like( $@, qr/Assertion.*failed/ ); 65 66# undef string fails 67eval { 68 assert_in( undef, [ 'fail' ] ); 69}; 70like( $@, qr/Assertion.*failed/ ); 71 72# empty array fails 73eval { 74 assert_in( 'empty', [ ] ); 75}; 76like( $@, qr/Assertion.*failed/ ); 77 78# undef for the arrayref fails 79eval { 80 my $string = 'zippo'; 81 assert_in( $string, undef ); 82}; 83like( $@, qr/Assertion.*failed/ ); 84 85# A bad reference should also fail. 86eval { 87 my $string = 'nil'; 88 my $ref = \$string; 89 assert_in( $string, $ref ); 90}; 91like( $@, qr/Assertion.*failed/ ); 92