summaryrefslogtreecommitdiffstats
path: root/t/001-basic-matching.t
blob: 52003acec71c8cb3b6f8c33b3a8d3c01f7dc5f4f (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 5;

package Foo;
use Moose;
with 'MooseX::Role::Matcher';

has [qw/a b c/] => (
    is       => 'ro',
    isa      => 'Str',
);

package main;
my $foo = Foo->new(a => 'foo', b => 'bar', c => 'baz');
ok($foo->match(a => 'foo', b => 'bar', c => 'baz'),
   'string matching works');
ok($foo->match(a => qr/o/),
   'regex matching works');
ok($foo->match(b => sub { length(shift) == 3 }),
   'subroutine matching works');
ok($foo->match(a => 'foo', b => qr/a/, c => sub { substr(shift, 2) eq 'z' }),
   'combined matching works');
$foo = Foo->new(a => 'foo');
ok($foo->match(a => 'foo', b => undef),
   'matching against undef works');