summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-02-04 19:46:16 -0500
committerdoy <doy@tozt.net>2009-02-04 19:46:16 -0500
commit0c724a1b3bb63754de5f428ad10f2d62fa4a0a86 (patch)
treee342b4a0d36772fafc010e85c7dfe2230d99aa6c /t
parent91b4279c62901f7be44cd1724044fe448a0c96d8 (diff)
downloadmoosex-role-matcher-0c724a1b3bb63754de5f428ad10f2d62fa4a0a86.tar.gz
moosex-role-matcher-0c724a1b3bb63754de5f428ad10f2d62fa4a0a86.zip
add a test for the synopsis
Diffstat (limited to 't')
-rw-r--r--t/005-synopsis.t39
1 files changed, 39 insertions, 0 deletions
diff --git a/t/005-synopsis.t b/t/005-synopsis.t
new file mode 100644
index 0000000..eebf301
--- /dev/null
+++ b/t/005-synopsis.t
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+package Person;
+use Moose;
+with 'MooseX::Role::Matcher' => { default_match => 'name' };
+
+has name => (is => 'ro', isa => 'Str');
+has age => (is => 'ro', isa => 'Num');
+has phone => (is => 'ro', isa => 'Str');
+
+package main;
+my @people = (
+ Person->new(name => 'James', age => 22, phone => '555-1914'),
+ Person->new(name => 'Jesse', age => 22, phone => '555-6287'),
+ Person->new(name => 'Eric', age => 21, phone => '555-7634'),
+);
+
+# is James 22?
+ok($people[0]->match(age => 22), "James is 22");
+
+# which people are not 22?
+is_deeply([Person->grep_matches([@people], '!age' => 22)],
+ [$people[2]], "Eric is not 22");
+
+# do any of the 22-year-olds have a phone number ending in 4?
+ok(Person->any_match([@people], age => 22, phone => qr/4$/),
+ "James is 22 and has a phone number ending in 4");
+
+# does everyone's name start with either J or E?
+ok(Person->all_match([@people], name => [qr/^J/, qr/^E/]),
+ "everyone's name starts with either J or E");
+
+# find the first person whose name is 4 characters long (using the
+# default_match of name)
+is(Person->first_match([@people], sub { length == 4 }), $people[2],
+ "Eric is the first person whose name is 4 characters long");