From ca7642226a2992e3cc4e4e8345a0fe5be6fef38c Mon Sep 17 00:00:00 2001 From: doy Date: Sat, 6 Dec 2008 23:20:53 -0500 Subject: more tests --- t/003-methods.t | 26 ++++++++++++++++++++++++ t/101-parameterized.t | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 t/003-methods.t create mode 100644 t/101-parameterized.t diff --git a/t/003-methods.t b/t/003-methods.t new file mode 100644 index 0000000..c4c0d5f --- /dev/null +++ b/t/003-methods.t @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 2; + +package Foo; +use Moose; +with 'MooseX::Role::Matcher'; + +has [qw/a b c/] => ( + is => 'ro', + isa => 'Str', + required => 1, +); + +sub concat { + my $self = shift; + return $self->a . $self->b . $self->c; +} + +package main; +my $foo = Foo->new(a => 'foo', b => 'bar', c => 'baz'); +ok($foo->match(concat => 'foobarbaz'), + 'match handles methods as well as attributes'); +ok($foo->match(a => qr/o/, concat => sub { length(shift) > 6 }), + 'match handles methods as well as attributes'); diff --git a/t/101-parameterized.t b/t/101-parameterized.t new file mode 100644 index 0000000..53f6d4e --- /dev/null +++ b/t/101-parameterized.t @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 1; +use Test::Deep; + +package Foo; +use Moose; +with 'MooseX::Role::Matcher' => { default_match => 'a' }; + +has [qw/a b c/] => ( + is => 'ro', + isa => 'Str', + required => 1, +); + +package FooCollection; +use Moose; + +has foos => ( + is => 'rw', + isa => 'ArrayRef[Foo]', + default => sub { [] }, +); + +sub first_match { + my $self = shift; + Foo->first_match($self->foos, @_); +} + +sub any_match { + my $self = shift; + Foo->any_match($self->foos, @_); +} + +sub all_match { + my $self = shift; + Foo->all_match($self->foos, @_); +} + +sub grep_matches { + my $self = shift; + Foo->grep_matches($self->foos, @_); +} + +package main; +my $foos = FooCollection->new; +my $foo1 = Foo->new(a => 'foo', b => 'bar', c => 'baz'); +my $foo2 = Foo->new(a => '', b => '3', c => 'foobar'); +my $foo3 = Foo->new(a => 'blah', b => 'abc', c => 'foo'); +push @{ $foos->foos }, $foo1; +push @{ $foos->foos }, $foo2; +push @{ $foos->foos }, $foo3; +is($foos->first_match(sub { length(shift) < 3 }), $foo2, + 'default parameter is passed correctly'); -- cgit v1.2.3