Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nics committed Mar 13, 2012
1 parent 4d4ac55 commit f9c7a73
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Build.PL
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ my $recommends = {
}; };


my $auto_features = { my $auto_features = {
cmd_repl => {
description => "REPL",
requires => {
'Devel::REPL' => '1.003012',
},
},
store_dbi => { store_dbi => {
description => "Store backed by DBI", description => "Store backed by DBI",
requires => { requires => {
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Buffer.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sub buffer_used {


sub buffer_is_full { sub buffer_is_full {
my $self = $_[0]; my $self = $_[0];
$self->buffer_used >= $self->buffer_size; $self->buffer_used >= $self->buffer_size ? 1 : 0;
} }


sub buffer_add { sub buffer_add {
Expand Down
6 changes: 1 addition & 5 deletions lib/Catmandu/Counter.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ sub inc_count {
} }


sub dec_count { sub dec_count {
my $self = $_[0]; my $self = $_[0]; $self->{count} ? --$self->{count} : 0;
if ($self->{count}) {
return --$self->{count};
}
0;
} }


sub reset_count { sub reset_count {
Expand Down
41 changes: 40 additions & 1 deletion t/Catmandu-Buffer.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,5 +16,44 @@ BEGIN {
} }
require_ok $pkg; 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;


6 changes: 3 additions & 3 deletions t/Catmandu-Cmd-repl.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use Test::Exception;


my $pkg; my $pkg;
BEGIN { BEGIN {
#unless (Catmandu::ConfigData->feature('')) { unless (Catmandu::ConfigData->feature('cmd_repl')) {
# plan skip_all => 'feature disabled'; plan skip_all => 'feature disabled';
#} }
$pkg = 'Catmandu::Cmd::repl'; $pkg = 'Catmandu::Cmd::repl';
use_ok $pkg; use_ok $pkg;
} }
Expand Down
31 changes: 30 additions & 1 deletion t/Catmandu-Counter.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,5 +16,34 @@ BEGIN {
} }
require_ok $pkg; 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.