X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-flatten.t;h=e4109214d01fd5dc3e40a98c404ba1b14064b428;hb=ea95d5eb42f17626bfca0f26e58a7d6c28e74d47;hp=05f56e7fa35f5fb97c1098a0018c03cf4ebf4838;hpb=4b145ee918e94698fe49c6e9240d50cfb2a36c75;p=perl%2Fmodules%2FSub-Prototype-Util.git diff --git a/t/10-flatten.t b/t/10-flatten.t index 05f56e7..e410921 100644 --- a/t/10-flatten.t +++ b/t/10-flatten.t @@ -3,18 +3,28 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 27; -use Sub::Prototype::Util qw/flatten/; +use Sub::Prototype::Util qw; +sub exception { + my ($msg) = @_; + $msg =~ s/\s+/\\s+/g; + return qr/^$msg.*?at\s+\Q$0\E\s+line\s+\d+/; +} + +eval { flatten '$' }; +like $@, exception('Not enough arguments to match this prototype'), + 'flatten("$") croaks'; eval { flatten '\@', undef }; -like($@, qr/^Got\s+undef/, 'flatten "\@", undef croaks'); +like $@, exception('Got undef'), 'flatten "\@", undef croaks'; eval { flatten '\@', 1 }; -like($@, qr/^Got\s+a\s+plain\s+scalar/, 'flatten "\@", scalar croaks'); +like $@, exception('Got a plain scalar'), 'flatten "\@", scalar croaks'; eval { flatten '\@', { foo => 1 } }; -like($@, qr/^Unexpected\s+HASH\s+reference/, 'flatten "\@", hashref croaks'); +like $@, exception('Unexpected HASH reference'), 'flatten "\@", hashref croaks'; eval { flatten '\@', \(\1) }; -like($@, qr/^Unexpected\s+REF\s+reference/, 'flatten "\@", double ref croaks'); +like $@, exception('Unexpected REF reference'), + 'flatten "\@", double ref croaks'; my $a = [ 1, 2, 3 ]; my $b = [ [ 1, 2 ], 3, { 4 => 5 }, undef, \6 ]; @@ -40,10 +50,8 @@ my @tests = ( [ '\&$', 'coderef', [ \&main::hlagh, 1 ], [ 'HLAGH', 1 ] ], [ '\[$@%]', 'class got scalarref', [ \1 ], [ 1 ] ], [ '\[$@%]', 'class got arrayref', [ [ 1 ] ], [ 1 ] ], - [ '\[$@%]', 'class got hashref', [ { 1,2 } ], [ 1, 2 ] ] + [ '\[$@%]', 'class got hashref', [ { 1,2 } ], [ 1, 2 ] ], + [ '_', '_ with argument', [ 1, 2 ], [ 1 ] ], ); -my $l = [ '_', '$_', [ ] ]; -$l->[3] = [ $l ]; -push @tests, $l; is_deeply( [ flatten($_->[0], @{$_->[2]}) ], $_->[3], $_->[1]) for @tests;