summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-02-10 14:11:47 +0100
committerfranck cuny <franck@lumberjaph.net>2010-02-10 14:11:47 +0100
commit3cf29ca9877089a8a26dcf16a9d757f681a42eba (patch)
tree1b9031d7085aaca0d04492e93544d2f0f072ac7c
parentexport private and protected (diff)
downloadmoosex-privacy-3cf29ca9877089a8a26dcf16a9d757f681a42eba.tar.gz
add basic tests
-rw-r--r--t/00_compile.t2
-rw-r--r--t/10_private_method.t59
-rw-r--r--t/11_protected_method.t40
3 files changed, 100 insertions, 1 deletions
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';