| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | use Test::Morescip-perl cpan autobox-Core 1.33 Test/More/ 'no_plan'; |
| 4 | use strictscip-perl cpan autobox-Core 1.33 strict/; |
| 5 | use warningsscip-perl cpan autobox-Core 1.33 warnings/; |
| 6 | |
| 7 | use autobox::Corescip-perl cpan autobox-Core 1.33 autobox/Core/; |
| 8 | |
| 9 | my @array = qw(1 2 3); |
| 10 | |
| 11 | my @odd = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().(sub { $_scip-perl cpan autobox-Core 1.33 main/$_. % 2 }); |
| 12 | |
| 13 | is_deeply \@odd, [qw(1 3)], "Expected coderef grep results"; |
| 14 | |
| 15 | my $arrayref = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().( sub { 'foo' } ); |
| 16 | |
| 17 | isscip-perl cpan autobox-Core 1.33 main/is(). refscip-perl cpan autobox-Core 1.33 main/ref(). $arrayref, 'ARRAY', "Returns arrayref in scalar context"; |
| 18 | |
| 19 | @array = qw( foo bar baz ); |
| 20 | my $d; |
| 21 | |
| 22 | okscip-perl cpan autobox-Core 1.33 main/ok(). ( eval { @array->grepscip-perl cpan autobox-Core 1.33 main/grep().( sub { 42 } || 1) }, "Should accept code refs" ); |
| 23 | okscip-perl cpan autobox-Core 1.33 main/ok(). ( eval { @array->grepscip-perl cpan autobox-Core 1.33 main/grep().( qr/foo/ ) || 1 }, "Should accept Regexps" ); |
| 24 | |
| 25 | is_deeplyscip-perl cpan autobox-Core 1.33 main/is_deeply().( $d = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().('foo'), [qw( foo )], "Works with SCALAR" ); |
| 26 | is_deeplyscip-perl cpan autobox-Core 1.33 main/is_deeply().( $d = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().('zar'), [], "Works with SCALAR" ); |
| 27 | is_deeplyscip-perl cpan autobox-Core 1.33 main/is_deeply().( $d = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().(qr/^ba/), [qw( bar baz )], "Works with Regexp" ); |
| 28 | is_deeplyscip-perl cpan autobox-Core 1.33 main/is_deeply().( $d = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().(sub { /^ba/ }), [qw( bar baz )], "... as with Code refs" ); |
| 29 | |
| 30 | # context |
| 31 | my @d = @array->grepscip-perl cpan autobox-Core 1.33 main/grep().(qr/^ba/); |
| 32 | |
| 33 | isscip-perl cpan autobox-Core 1.33 main/is(). scalarscip-perl cpan autobox-Core 1.33 main/scalar(). @d, 2, "Returns an array in list context"; |