Browse files

more tests

  • Loading branch information...
1 parent 4d4ac55 commit f9c7a730f6b2aa8d76216da84c600c69bc46baa7 @nics nics committed Mar 13, 2012
Showing with 81 additions and 11 deletions.
  1. +6 −0 Build.PL
  2. +1 −1 lib/Catmandu/Buffer.pm
  3. +1 −5 lib/Catmandu/Counter.pm
  4. +40 −1 t/Catmandu-Buffer.t
  5. +3 −3 t/Catmandu-Cmd-repl.t
  6. +30 −1 t/Catmandu-Counter.t
View
6 Build.PL
@@ -37,6 +37,12 @@ my $recommends = {
};
my $auto_features = {
+ cmd_repl => {
+ description => "REPL",
+ requires => {
+ 'Devel::REPL' => '1.003012',
+ },
+ },
store_dbi => {
description => "Store backed by DBI",
requires => {
View
2 lib/Catmandu/Buffer.pm
@@ -18,7 +18,7 @@ sub buffer_used {
sub buffer_is_full {
my $self = $_[0];
- $self->buffer_used >= $self->buffer_size;
+ $self->buffer_used >= $self->buffer_size ? 1 : 0;
}
sub buffer_add {
View
6 lib/Catmandu/Counter.pm
@@ -10,11 +10,7 @@ sub inc_count {
}
sub dec_count {
- my $self = $_[0];
- if ($self->{count}) {
- return --$self->{count};
- }
- 0;
+ my $self = $_[0]; $self->{count} ? --$self->{count} : 0;
}
sub reset_count {
View
41 t/Catmandu-Buffer.t
@@ -16,5 +16,44 @@ BEGIN {
}
require_ok $pkg;
-done_testing 2;
+{
+ package T::Buffer;
+
+ use Moo;
+
+ with 'Catmandu::Buffer';
+}
+
+my $b = T::Buffer->new;
+
+can_ok $b, 'buffer_size';
+can_ok $b, 'buffer';
+can_ok $b, 'default_buffer_size';
+can_ok $b, 'buffer_used';
+can_ok $b, 'buffer_is_full';
+can_ok $b, 'buffer_add';
+can_ok $b, 'clear_buffer';
+
+is $b->buffer_size, $b->default_buffer_size;
+
+$b = T::Buffer->new(buffer_size => 5);
+is $b->buffer_size, 5;
+is $b->buffer_used, 0;
+
+$b->buffer_add(1,2,3);
+is $b->buffer_used, 3;
+is_deeply $b->buffer, [1,2,3];
+is $b->buffer_is_full, 0;
+
+$b->buffer_add(4,5,6);
+is $b->buffer_used, 6;
+is_deeply $b->buffer, [1,2,3,4,5,6];
+is $b->buffer_is_full, 1;
+
+$b->clear_buffer;
+is $b->buffer_used, 0;
+is_deeply $b->buffer, [];
+is $b->buffer_is_full, 0;
+
+done_testing 21;
View
6 t/Catmandu-Cmd-repl.t
@@ -8,9 +8,9 @@ use Test::Exception;
my $pkg;
BEGIN {
- #unless (Catmandu::ConfigData->feature('')) {
- # plan skip_all => 'feature disabled';
- #}
+ unless (Catmandu::ConfigData->feature('cmd_repl')) {
+ plan skip_all => 'feature disabled';
+ }
$pkg = 'Catmandu::Cmd::repl';
use_ok $pkg;
}
View
31 t/Catmandu-Counter.t
@@ -16,5 +16,34 @@ BEGIN {
}
require_ok $pkg;
-done_testing 2;
+{
+ package T::Counter;
+
+ use Moo;
+
+ with 'Catmandu::Counter';
+}
+
+my $c = T::Counter->new;
+
+can_ok $c, 'count';
+can_ok $c, 'inc_count';
+can_ok $c, 'dec_count';
+can_ok $c, 'reset_count';
+
+is $c->count, 0;
+
+$c->inc_count;
+is $c->count, 1;
+
+$c->dec_count;
+is $c->count, 0;
+$c->dec_count;
+is $c->count, 0;
+
+$c->inc_count;
+$c->reset_count;
+is $c->count, 0;
+
+done_testing 11;

0 comments on commit f9c7a73

Please sign in to comment.