File: multi.t

package info (click to toggle)
libmixin-extrafields-param-perl 0.011-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 96 kB
  • ctags: 6
  • sloc: perl: 181; makefile: 2
file content (90 lines) | stat: -rw-r--r-- 1,672 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
#!perl -T
use strict;
use warnings;

use Test::More tests => 15;

{
  package Widget::Parameterized;
  use Mixin::ExtraFields::Param
    -fields => { driver  => 'HashGuts' },
    -fields => {
      moniker => 'field',
      driver  => {
        class    => 'HashGuts',
        hash_key => 'field',
      }
    };

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

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

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

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

  my @names_fields = $widget->field;
  cmp_ok(@names_fields, '==', 0, "there are zero params_fields 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",
);

is(
  $widget->field('flavor'),
  undef,
  "...but it didn't affect the same-name field",
);

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

  my @names_fields = $widget->field;
  cmp_ok(@names_fields, '==', 0, "but still zero fields");
}

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

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

is(
  $widget->param('flavor'),
  'teaberry',
  "...but it didn't affect the same-name param",
);