summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-05-17 22:43:18 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-05-17 22:43:18 +0200
commit76a1ba5f056fbdce14054128faedb0512bfee2d0 (patch)
tree41988cb3e195cf6d4bc9e7cfc22923d8efae9372
parent2f99841240904b6a487c9216b410e3e34e8506ac (diff)
Begin work on App::Hashl tests
-rw-r--r--lib/App/Hashl.pm2
-rw-r--r--t/29-app-hashl.t30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm
index 3f9bfa7..58af4a6 100644
--- a/lib/App/Hashl.pm
+++ b/lib/App/Hashl.pm
@@ -51,7 +51,7 @@ sub si_size {
my ($self, $bytes) = @_;
my @post = (' ', qw(k M G T));
- while ($bytes > 1024) {
+ while ($bytes >= 1024) {
$bytes /= 1024;
shift @post;
}
diff --git a/t/29-app-hashl.t b/t/29-app-hashl.t
new file mode 100644
index 0000000..fbd2e99
--- /dev/null
+++ b/t/29-app-hashl.t
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+
+use Test::More tests => 13;
+
+use_ok('App::Hashl');
+
+my $hashl = App::Hashl->new();
+isa_ok($hashl, 'App::Hashl');
+
+is($hashl->read_size(), (2 ** 20) * 4, 'default read size');
+
+$hashl = App::Hashl->new(read_size => 512);
+
+is($hashl->read_size(), 512, 'Custom read size set');
+
+is($hashl->si_size(1023), '1023.0 ', 'si_size 1023 = 1023');
+is($hashl->si_size(1024), ' 1.0k', 'si_size 1024 = 1k');
+is($hashl->si_size(2048), ' 2.0k', 'si_size 2048 = 2k');
+
+
+is($hashl->hash_in_db('123'), undef, 'hash not in db');
+is($hashl->file_in_db('t/in/4'), undef, 'file not in db');
+is_deeply([$hashl->files()], [], 'no files in empty db');
+is_deeply([$hashl->ignored()], [], 'no ignored files in empty db');
+
+ok($hashl->ignore('hash123'), 'ignore hash');
+is_deeply([$hashl->ignored()], ['hash123'], 'ignore hash');