File: basic.t

package info (click to toggle)
libmixin-extrafields-param-perl 0.022-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 304; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,200 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
#!perl -T
use strict;
use warnings;

use Test::More tests => 11;

{
  package Widget::Parameterized;
  use Mixin::ExtraFields::Param -fields => { driver => 'HashGuts' };

  sub new { bless {} => shift; }
  sub id { 0 + $_[0] }
}

my $widget = Widget::Parameterized->new;

isa_ok($widget, 'Widget::Parameterized');
can_ok($widget, 'param');

{
  my @names = $widget->param;
  cmp_ok(@names, '==', 0, "there are zero params to start with");
}

is(
  $widget->param('flavor'),
  undef,
  "a specific param is also unset",
);

{
  my @names = $widget->param;
  cmp_ok(@names, '==', 0, "checking on a given param didn't create it");
}

is(
  $widget->param(flavor => 'teaberry'),
  'teaberry',
  "we set a param and got its value back",
);

is(
  $widget->param('flavor'),
  'teaberry',
  "...and that value stuck",
);

{
  my @names = $widget->param;
  cmp_ok(@names, '==', 1, "so now there is one param");
}

{
  my @values = $widget->param(size => 'big', limits => undef);
  cmp_ok(@values, '==', 2, "we get back two values");
  is_deeply(\@values, [ 'big', undef ], "...and they're the two set set");

  my @names = $widget->param;
  cmp_ok(@names, '==', 3, "we set two more, now there are three");
}