stringify version before comparing, as recommended by Zefram
[p5sagit/Try-Tiny.git] / t / when.t
CommitLineData
3176feef 1use strict;
f9d19a00 2use warnings;
3176feef 3
4use Test::More;
5
6BEGIN {
b715d61b 7 plan skip_all => 'Perl 5.010 is required' unless "$]" >= '5.010';
c6d66f74 8 plan tests => 5;
3176feef 9}
10
01b96275 11use Try::Tiny;
3176feef 12
13use 5.010;
8c34b0ef 14no if "$]" >= 5.017011, warnings => 'experimental::smartmatch';
3176feef 15
16my ( $foo, $bar, $other );
17
18$_ = "magic";
19
20try {
8d2ee831 21 die "foo";
3176feef 22} catch {
23
8d2ee831 24 like( $_, qr/foo/ );
3176feef 25
8d2ee831 26 when (/bar/) { $bar++ };
27 when (/foo/) { $foo++ };
28 default { $other++ };
3176feef 29};
30
31is( $_, "magic", '$_ not clobbered' );
32
33ok( !$bar, "bar didn't match" );
34ok( $foo, "foo matched" );
35ok( !$other, "fallback didn't match" );