File: basic.t

package info (click to toggle)
libmixin-extrafields-perl 0.140003-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 411; makefile: 2
file content (123 lines) | stat: -rw-r--r-- 2,974 bytes parent folder | download | duplicates (4)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use strict;
use warnings;

use Test::More tests => 29;

BEGIN { require_ok('Mixin::ExtraFields'); }

use lib 't/lib';

my $test_class;

BEGIN {
  $test_class = 'Object::HasExtraFields';
  use_ok($test_class);
}

my $object = $test_class->new;

isa_ok($object, $test_class);

can_ok(
  $object,
  map { "$_\_extra" } qw(get get_all set exists delete delete_all),
);

is_deeply(
  [ $object->get_all_extra ],
  [ ],
  "when we begin, there are no extras",
);

is_deeply(
  [ $object->get_all_detailed_extra ],
  [ ],
  "...even if we ask for all the details",
);

ok( ! $object->exists_extra('datum'), "there exists no extra 'datum' yet");
is($object->get_extra('datum'), undef, "extra 'datum' shows undef value");
is($object->get_detailed_extra('datum'), undef, "...even with _detailed_");
ok( ! $object->exists_extra('datum'), "getting 'datum' value doesn't autoviv");

$object->set_extra(datum => 10);

ok($object->exists_extra('datum'), "extra 'datum' exists now");
is($object->get_extra('datum'), 10, "extra/datum has the value we supplied");

is(
  $object->{_extra}{datum},
  10,
  "with a fixed hash key, we can go find extras in the hash guts",
);

ok( ! $object->exists_misc('datum'), "there exists no misc 'datum' yet");
is($object->get_misc('datum'), undef, "misc/datum has the value we supplied");

$object->set_misc(datum => 20);

ok($object->exists_misc('datum'), "there now exists misc 'datum'");
is($object->get_misc('datum'), 20, "misc/datum has the value we supplied");

is($object->get_extra('datum'), 10, "extra/datum has the value we supplied");

$object->delete_extra('datum');

ok( ! $object->exists_extra('datum'), "there exists no extra 'datum' again");
is($object->get_extra('datum'), undef, "extra 'datum' shows undef value");

is_deeply(
  [ $object->get_all_misc_names ],
  [ qw(datum) ],
  "get_all_misc_names gets the one name that it should",
);

is_deeply(
  [ $object->get_all_misc ],
  [ datum => 20 ],
  "get_all_misc gets the one pair that it should",
);

is_deeply(
  [ $object->get_detailed_misc('datum') ],
  [ { value => 20 } ],
  "get_detailed_misc gets the hashref that it should",
);

is_deeply(
  [ $object->get_all_detailed_misc ],
  [ datum => { value => 20 } ],
  "get_all_detailed_misc gets the one pair that it should",
);

$object->set_extra(datum => 10);

is_deeply(
  [ $object->get_all_detailed_extra ],
  [ datum => { value => 10 } ],
  "get_all_detailed_extra gets the one pair that it should",
);

my $other = $test_class->new;
is_deeply(
  [ $other->get_all_detailed_misc ],
  [ ],
  "...but gets nothing from a new obj"
);

is_deeply(
  [ $other->get_all_detailed_extra ],
  [ datum => { value => 10 } ],
  "...but get_all_detailed_extra does!  it uses a shared id"
);

$object->delete_all_misc;

is_deeply(
  [ $object->get_all_misc ],
  [ ],
  "after delete_all_misc, get_all_misc gets nothing",
);

eval { (ref $object)->get_all_misc };
like($@, qr/couldn't determine id/, "exception thrown if called on class");