BusyBird
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Test::Memory::Cycle;
use lib "t";
use testlib::Timeline_Util qw(status sync);
use testlib::Main_Util qw(create_main);
use BusyBird::Test::StatusStorage qw(:status);
use BusyBird::StatusStorage::SQLite;
use BusyBird::Timeline;
use BusyBird::Log;
use utf8;
BEGIN {
use_ok('BusyBird::Main');
}
$BusyBird::Log::Logger = undef;
sub test_watcher_basic {
my ($watcher) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
isa_ok($watcher, 'BusyBird::Watcher');
can_ok($watcher, 'active', 'cancel');
}
sub create_memory_storage {
return BusyBird::StatusStorage::SQLite->new(path => ':memory:');
}
{
my $main = new_ok('BusyBird::Main');
my $storage = create_memory_storage();
$main->set_config(default_status_storage => $storage);
is($main->get_config("default_status_storage"), $storage, 'setting default_status_storage OK');
}
{
my $main = create_main();
is_deeply([$main->get_all_timelines], [], 'at first, no timelines');
my $tl1 = $main->timeline('test1');
isa_ok($tl1, 'BusyBird::Timeline', 'timeline() creates a timeline');
is($tl1->name, 'test1', "... its name is test1");
is_deeply([$main->get_all_timelines], [$tl1], 'test1 is installed,.');
is($main->timeline('test1'), $tl1, 'timeline() returns the installed timeline');
is($main->get_timeline('test1'), $tl1, 'get_timeline() returns the installed timeline');
is($main->get_timeline('foobar'), undef, 'get_timeline() returns undef if the timeline is not installed.');
my $tl2 = BusyBird::Timeline->new(name => 'foobar', storage => create_memory_storage());
$main->install_timeline($tl2);
is($main->get_timeline('foobar'), $tl2, 'install_timeline() installs a timeline');
is($main->timeline('foobar'), $tl2, 'timeline() returns the installed timeline');
is_deeply([$main->get_all_timelines], [$tl1, $tl2], "get_all_timelines() return the two timelines");
is($main->uninstall_timeline('hogehoge'), undef, 'uninstall_timeline() returns undef it the timeline is not installed');
is($main->uninstall_timeline('test1'), $tl1, 'uninstall test1 timeline');
is($main->get_timeline('test1'), undef, 'now test1 is not installed');
is_deeply([$main->get_all_timelines], [$tl2], 'now only foobar is installed.');
my $tl3 = BusyBird::Timeline->new(name => 'foobar', storage => create_memory_storage());
$main->install_timeline($tl3);
is($main->get_timeline('foobar'), $tl3, 'install_timeline() replaces the old timeline with the same name');
( run in 1.792 second using v1.01-cache-2.11-cpan-54e63673c56 )