File: 80match-is.t

package info (click to toggle)
libsyntax-operator-is-perl 0.02-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 108; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

BEGIN {
   plan skip_all => "Syntax::Keyword::Match >= 0.08 is not available"
   unless eval { require Syntax::Keyword::Match;
                 Syntax::Keyword::Match->VERSION( '0.08' ); };
   plan skip_all => "Syntax::Operator::Is is not available"
   unless eval { require Syntax::Operator::Is };

   Syntax::Keyword::Match->import;
   Syntax::Operator::Is->import;

   diag( "Syntax::Keyword::Match $Syntax::Keyword::Match::VERSION, " .
         "Syntax::Operator::Is $Syntax::Operator::Is::VERSION" );
}

# if we have Syntax::Operator::Is available then we know we must have
# Data::Checks as well
use Data::Checks qw( Num Object );

{
   sub func
   {
      match( $_[0] : is ) {
         case( Num    ) { return "arg is a number" }
         case( Object ) { return "arg is an object" }
         default        { return "arg is neither" }
      }
   }

   Test2::V0::is( func( 123 ),                   "arg is a number",  'func() on number' );
   Test2::V0::is( func( bless [], "SomeClass" ), "arg is an object", 'func() on object' );
   Test2::V0::is( func( [] ),                    "arg is neither",   'func() on arrayref' );
}

done_testing;