summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/Test-Simple/t/Test2/modules/Util/ExternalMeta.t
blob: bd9812fc377caa8d56ed5b001ca21d6c8f49d385 (plain) (blame)
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
66
67
68
69
70
use strict;
use warnings;
use Test2::Tools::Tiny;

{
    package Foo::Bar;

    use Test2::Util::ExternalMeta;
    use Test2::Util::HashBase qw/foo bar/;
}

ok(Foo::Bar->can($_), "Imported '$_'") for qw/meta get_meta set_meta delete_meta/;

my $one = Foo::Bar->new(foo => 1, bar => 2);
ok($one->isa('Foo::Bar'), "Got instance");

is_deeply($one, {foo => 1, bar => 2}, "nothing fishy.. yet");

is($one->get_meta('foo'), undef, "no meta-data for foo");
is($one->get_meta('bar'), undef, "no meta-data for bar");
is($one->get_meta('baz'), undef, "no meta-data for baz");

is($one->meta('foo'), undef, "no meta-data for foo");
is($one->meta('bar'), undef, "no meta-data for bar");
is($one->meta('baz'), undef, "no meta-data for baz");

is_deeply($one, {foo => 1, bar => 2}, "Still have not modified instance");

$one->set_meta('foo' => 123);
is($one->foo, 1, "did not change attribute");
is($one->meta('foo'), 123, "get meta-data for foo");
is($one->get_meta('foo'), 123, "get meta-data for foo again");

$one->meta('foo', 345);
is($one->foo, 1, "did not change attribute");
is($one->meta('foo', 678), 123, "did not alter already set meta-attribute");
is($one->get_meta('foo'), 123, "still did not alter already set meta-attribute");

is($one->meta('bar', 789), 789, "used default for bar");
is($one->bar, 2, "did not change attribute");

is_deeply(
    $one,
    {
        foo => 1,
        bar => 2,
        Test2::Util::ExternalMeta::META_KEY() => {
            foo => 123,
            bar => 789,
        },
    },
    "Stored meta-data"
);

is($one->delete_meta('foo'), 123, "got old value on delete");
is($one->meta('foo'), undef, "no more value");

is_deeply(
    $one,
    {
        foo => 1,
        bar => 2,
        Test2::Util::ExternalMeta::META_KEY() => {
            bar => 789,
        },
    },
    "Deleted the meta key"
);

done_testing;