1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/usr/bin/perl
use strict;
use warnings;
use Fennec::Lite;
our $CLASS;
BEGIN {
$CLASS = 'Meta::Builder';
require_ok $CLASS;
}
{
package MyMeta;
use Meta::Builder;
accessor 'mymeta';
hash_metric 'myhash';
lists_metric 'mylists';
}
tests merge => sub {
my $meta = MyMeta->new( 'FAKEA' );
my $other = MyMeta->new( 'FAKEB' );
$meta->myhash_add( 'a' => 'b' );
$meta->myhash_add( 'b' => 'c' );
$meta->mylists_push( a => qw/a b c/ );
$other->myhash_add( 'c' => 'd' );
$other->myhash_add( 'd' => 'e' );
$other->mylists_push( a => qw/d e f/ );
$meta->merge( $other );
is_deeply(
$meta->myhash,
{
a => 'b',
b => 'c',
c => 'd',
d => 'e',
},
"Merged hash",
);
is_deeply(
$meta->mylists,
{ a => [qw/a b c d e f/] },
"Merged lists",
);
};
tests fail => sub {
my $meta = MyMeta->new( 'FAKEC' );
my $other = MyMeta->new( 'FAKED' );
$meta->myhash_add( 'a' => 'b' );
$other->myhash_add( 'a' => 'd' );
throws_ok { $meta->merge( $other )}
qr/a is defined for myhash in both meta-objects/,
"Cannot merge hashes with the same keys";
};
run_tests();
done_testing;
|