From 3cf29ca9877089a8a26dcf16a9d757f681a42eba Mon Sep 17 00:00:00 2001 From: franck cuny Date: Wed, 10 Feb 2010 14:11:47 +0100 Subject: add basic tests --- t/00_compile.t | 2 +- t/10_private_method.t | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ t/11_protected_method.t | 40 +++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 t/10_private_method.t create mode 100644 t/11_protected_method.t (limited to 't') diff --git a/t/00_compile.t b/t/00_compile.t index d67722e..14cc741 100644 --- a/t/00_compile.t +++ b/t/00_compile.t @@ -1,4 +1,4 @@ use strict; use Test::More tests => 1; -BEGIN { use_ok 'MooseX::Privacy' } +BEGIN { use Moose; use_ok 'MooseX::Privacy' } diff --git a/t/10_private_method.t b/t/10_private_method.t new file mode 100644 index 0000000..231ba42 --- /dev/null +++ b/t/10_private_method.t @@ -0,0 +1,59 @@ +use strict; +use warnings; + +use Test::More tests => 7; +use Test::Exception; + +{ + + package Foo; + use Moose; + use MooseX::Privacy; + + private 'bar' => sub { + my $self = shift; + return 'baz'; + }; + + sub baz { + my $self = shift; + return $self->bar; + } + + sub foo { + my $self = shift; + return $self->foobar(shift); + } + + private 'foobar' => sub { + my $self = shift; + my $str = shift; + return 'foobar' . $str; + }; + +} + +{ + + package Bar; + use Moose; + extends 'Foo'; + + sub newbar { + my $self = shift; + return $self->bar; + } +} + +my $foo = Foo->new(); +isa_ok( $foo, 'Foo' ); +dies_ok { $foo->bar } "... can't call bar, method is private"; +is $foo->baz, 'baz', "... got the good value from &baz"; +is $foo->foo('baz'), 'foobarbaz', "... got the good value from &foobar"; + +my $bar = Bar->new(); +isa_ok( $bar, 'Bar' ); +dies_ok { $bar->newbar() } "... can't call bar, method is private"; + +is scalar @{ $foo->meta->local_private_methods }, 2, + '... got two privates method'; diff --git a/t/11_protected_method.t b/t/11_protected_method.t new file mode 100644 index 0000000..2d86605 --- /dev/null +++ b/t/11_protected_method.t @@ -0,0 +1,40 @@ +use strict; +use warnings; + +use Test::More tests => 5; +use Test::Exception; + +{ + + package Foo; + use Moose; + use MooseX::Privacy; + + protected 'bar' => sub { + my $self = shift; + return 'baz'; + }; +} + +{ + + package Bar; + use Moose; + extends 'Foo'; + + sub baz { + my $self = shift; + return $self->bar; + } +} + +my $foo = Foo->new(); +isa_ok( $foo, 'Foo' ); +dies_ok { $foo->bar } "... can't call bar, method is protected"; + +my $bar = Bar->new(); +isa_ok( $bar, 'Bar' ); +is $bar->baz(), 'baz', "... got the good value from &bar"; + +is scalar @{ $foo->meta->local_protected_methods }, 1, + '... got one protected method'; -- cgit v1.2.3