From ef9e9eeca018131c99552c07b50684148e729dca Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 21 Sep 2009 01:31:21 -0500 Subject: add a bunch more tests --- t/002-add-traits.t | 47 ++++++++++++++++++++++++++++++++++++++++++ t/003-method-trait-options.t | 42 +++++++++++++++++++++++++++++++++++++ t/004-generate-method.t | 49 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 t/002-add-traits.t create mode 100644 t/003-method-trait-options.t create mode 100644 t/004-generate-method.t diff --git a/t/002-add-traits.t b/t/002-add-traits.t new file mode 100644 index 0000000..f3bb92c --- /dev/null +++ b/t/002-add-traits.t @@ -0,0 +1,47 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 4; +use Test::Moose; + +BEGIN { + package Foo::Exporter; + use MooseX::MethodTraits; + + MooseX::MethodTraits->setup_import_methods( + with_traits => { + command => { + traits => ['Foo::Command'], + }, + other => { + traits => ['Foo::OtherTrait'], + }, + }, + ); +} + +{ + package Foo::Command; + use Moose::Role; +} + +{ + package Foo::OtherTrait; + use Moose::Role; +} + +{ + package Foo; + use Moose; + BEGIN { Foo::Exporter->import } + + command foo => sub { 'FOO' }; + other 'foo'; +} + +my $foo = Foo->new; +can_ok($foo, 'foo'); +my $method = Foo->meta->get_method('foo'); +does_ok($method, 'Foo::Command'); +does_ok($method, 'Foo::OtherTrait'); +is($foo->foo, 'FOO', 'correct method is installed'); diff --git a/t/003-method-trait-options.t b/t/003-method-trait-options.t new file mode 100644 index 0000000..53403de --- /dev/null +++ b/t/003-method-trait-options.t @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 4; +use Test::Moose; + +BEGIN { + package Foo::Exporter; + use MooseX::MethodTraits; + + MooseX::MethodTraits->setup_import_methods( + with_traits => { + command => { + traits => ['Foo::Command'], + } + } + ); +} + +{ + package Foo::Command; + use Moose::Role; + + has bar => ( + is => 'ro', + ); +} + +{ + package Foo; + use Moose; + BEGIN { Foo::Exporter->import } + + command foo => sub { 'FOO' }, bar => 'BAR'; +} + +my $foo = Foo->new; +can_ok($foo, 'foo'); +my $method = Foo->meta->get_method('foo'); +does_ok($method, 'Foo::Command'); +is($foo->foo, 'FOO', 'correct method is installed'); +is($method->bar, 'BAR', 'method trait attribute is initialized'); diff --git a/t/004-generate-method.t b/t/004-generate-method.t new file mode 100644 index 0000000..999fd1e --- /dev/null +++ b/t/004-generate-method.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 4; +use Test::Moose; + +BEGIN { + package Foo::Exporter; + use MooseX::MethodTraits; + + MooseX::MethodTraits->setup_import_methods( + with_traits => { + alias => { + traits => ['Foo::Alias'], + munge => sub { + my $name = shift; + return sub { shift->$name(@_) }, + [ aliased_from => $name, @_ ]; + }, + } + } + ); +} + +{ + package Foo::Alias; + use Moose::Role; + + has aliased_from => ( + is => 'ro', + isa => 'Str', + ); +} + +{ + package Foo; + use Moose; + BEGIN { Foo::Exporter->import } + + sub foo { 'FOO' } + alias bar => 'foo'; +} + +my $foo = Foo->new; +can_ok($foo, 'bar'); +my $method = Foo->meta->get_method('bar'); +does_ok($method, 'Foo::Alias'); +is($method->aliased_from, 'foo', 'method knows where it came from'); +is($foo->bar, 'FOO', 'aliased properly'); -- cgit v1.2.3