File: 03-introspection.t

package info (click to toggle)
libmoosex-classattribute-perl 0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 372 kB
  • ctags: 47
  • sloc: perl: 1,148; makefile: 2
file content (108 lines) | stat: -rw-r--r-- 2,689 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use strict;
use warnings;

use lib 't/lib';

use Test::More;

# We just want the class definitions in here.
use SharedTests;

ok(
    HasClassAttribute->meta()->has_class_attribute('ObjectCount'),
    q{has_class_attribute('ObjectCount') returns true}
);

ok(
    HasClassAttribute->meta()->get_class_attribute('ObjectCount')->meta()
        ->does_role('MooseX::ClassAttribute::Trait::Attribute'),
    'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Trait::Attribute role'
);

my @ca = qw( Delegatee
    LazyAttribute
    ManyNames
    Mapping
    ObjectCount
    ReadOnlyAttribute
    WeakAttribute
    Built
    LazyBuilt
    Triggerish
    TriggerRecord
);

is_deeply(
    [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
    [ sort @ca ],
    'HasClassAttribute get_class_attribute_list gets all class attributes'
);

is_deeply(
    [
        sort map { $_->name() }
            HasClassAttribute->meta()->get_all_attributes()
    ],
    ['size'],
    'HasClassAttribute get_all_attributes only finds size attribute'
);

is_deeply(
    [
        sort map { $_->name() }
            HasClassAttribute->meta()->get_all_class_attributes()
    ],
    [ sort @ca ],
    'HasClassAttribute get_all_class_attributes gets all class attributes'
);

is_deeply(
    [ sort keys %{ HasClassAttribute->meta()->get_class_attribute_map() } ],
    [ sort @ca ],
    'HasClassAttribute get_class_attribute_map gets all class attributes'
);

is_deeply(
    [ sort map { $_->name() } Child->meta()->get_all_class_attributes() ],
    [ sort ( @ca, 'YetAnotherAttribute' ) ],
    'Child get_class_attribute_map gets all class attributes'
);

ok(
    !Child->meta()->has_class_attribute('ObjectCount'),
    q{has_class_attribute('ObjectCount') returns false for Child}
);

ok(
    Child->meta()->has_class_attribute('YetAnotherAttribute'),
    q{has_class_attribute('YetAnotherAttribute') returns true for Child}
);

ok(
    Child->can('YetAnotherAttribute'),
    'Child has accessor for YetAnotherAttribute'
);

ok(
    Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
    'Child has class attribute value for YetAnotherAttribute'
);

Child->meta()->remove_class_attribute('YetAnotherAttribute');

ok(
    !Child->meta()->has_class_attribute('YetAnotherAttribute'),
    q{... has_class_attribute('YetAnotherAttribute') returns false after remove_class_attribute}
);

ok(
    !Child->can('YetAnotherAttribute'),
    'accessor for YetAnotherAttribute has been removed'
);

ok(
    !Child->meta()->has_class_attribute_value('YetAnotherAttribute'),
    'Child does not have a class attribute value for YetAnotherAttribute'
);

done_testing();