Ambrosia
view release on metacpan or search on metacpan
t/Ambrosia/core/Object.t view on Meta::CPAN
#!/usr/bin/perl
use Test::More tests => 23;
use Test::Exception;
use Test::Deep;
use Data::Dumper;
use lib qw(lib t ../..);
BEGIN {
use_ok( 'Ambrosia::Meta' ); #test #1
}
require_ok( 'Ambrosia::Meta' ); #test #2
BEGIN {
use_ok( 'Ambrosia::core::Object' ); #test #3
}
require_ok( 'Ambrosia::core::Object' ); #test #4
use t::Foo;
use t::Bar;
#test create the object
my $my_foo = new_ok t::Foo => [foo_pub1 => 1, foo_pro1 => 2, foo_pri1 => 3]; #test #5
#test access to fields of the object
cmp_ok($my_foo->foo_pub1, '==', 1, 'Public field of Foo.'); #test #6
$my_foo->foo_pub1 = 321;
cmp_ok($my_foo->foo_pub1, '==', 321, 'Public field of Foo.'); #test #7
throws_ok { $my_foo->foo_pro1 } 'Ambrosia::error::Exception::AccessDenied', 'Ambrosia::error::Exception::AccessDenied to protected fields exception thrown'; #test #8
throws_ok { $my_foo->foo_pri1 } 'Ambrosia::error::Exception::AccessDenied', 'Ambrosia::error::Exception::AccessDenied to private fields exception thrown'; #test #9
#test methods of the object
#test static methods
my $H = {foo_pub1 => 1, foo_pub2 => 1, bar_pub1 => 1, bar_pub2 => 1};
my $my_bar = new_ok t::Bar => []; #test #11
cmp_deeply({map {$_ => 1} $my_bar->fields()}, $H, 'fields() is ok'); #test #12
my $string_dump = $my_bar->string_dump();
like($string_dump, '/^\^Storable|||hex|Compress::Zlib\^[a-z0-9]+$/', "string_dump looks good"); #test #13
my $hBar = $my_bar->as_hash(1, qw/
get_list_pri:getListPri
get_list_pro:getListPro
get_list_pri_ex:getListPriEx
get_list_pro_ex:getListProEx
el_pro{0}
el_pro:EL1{1}
/, "twice_pro");
my $asHash = {
'foo_pub2' => 'foo_pub2',
'foo_pub1' => 'foo_pub1',
'bar_pub1' => 'bar_pub1',
'bar_pub2' => 'bar_pub2',
'getListPri' => [
{
'foo_pub1' => 'Plist1.1',
'foo_pub2' => 'Plist1.2',
},
{
'foo_pub1' => 'Plist2.1',
'foo_pub2' => 'Plist2.2',
}
],
'getListPro' => [
{
'foo_pub1' => 'pro list1.1',
'foo_pub2' => 'pro list1.2',
},
{
'foo_pub1' => 'pro list2.1',
'foo_pub2' => 'pro list2.2',
}
],
'getListPriEx' => [
{
'foo_pub1' => 'Plist1.1',
'foo_pub2' => 'Plist1.2',
},
{
'foo_pub1' => 'Plist2.1',
'foo_pub2' => 'Plist2.2',
}
],
'getListProEx' => [
{
( run in 0.690 second using v1.01-cache-2.11-cpan-ceb78f64989 )