File Coverage

t/bind_data.t
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1 1     1   7 use strict;
  1         1  
  1         31  
2 1     1   5 use warnings;
  1         3  
  1         24  
3              
4 1     1   615 use Test::More;
  1         101650  
  1         22  
5 1     1   836 use Test::Warnings;
  1         1991  
  1         4  
6              
7 1     1   120 use_ok 'XML::BindData';
  1         644  
  1         59462  
  1         3  
  1         23  
8              
9 1         672 my $tests = [
10             [
11             '', { foo => 'bar' },
12             'bar', 'Single binding'
13             ],
14              
15             [
16             '', { foo => undef },
17             '', 'Single binding, undefined - get empty string'
18             ],
19              
20             [
21             '', { foo => 'bar' },
22             'bar', 'Single binding, with default (unused)'
23             ],
24              
25             [
26             '', {},
27             'baz', 'Single binding, with default (used)'
28             ],
29              
30             [
31             '', { foo => [(1) x 3] },
32             '',
33             'Each over multiple entities'
34             ],
35              
36             [
37             '',
38             { bar => [ 1, 2, 3 ] },
39             '123',
40             'This binds inside each'
41             ],
42              
43             [
44             '', { baz => 'quux' },
45             '', 'Attribute binds'
46             ],
47              
48             [
49             '', { aaa => 1, bbb => 2 },
50             '', 'Multiple attributes bind'
51             ],
52              
53             [
54             '', { aaa => 1, bbb => 2 },
55             '', 'Multiple attributes bind with undefined values'
56             ],
57              
58             [
59             '', { aaa => 1, bbb => 2 },
60             '', 'Attribute defaults'
61             ],
62              
63             [
64             '', { aaa => 0, bbb => 2 },
65             '', 'Attribute defaults with false values'
66             ],
67              
68             [
69             '', { aaa => undef, bbb => 2 },
70             '', 'Attribute defaults with undefined values'
71             ],
72              
73             [
74             '', { aaa => 0, bbb => 2 },
75             '', 'Attribute defaults with commas and colons'
76             ],
77              
78             [
79             '',
80             {
81             bar => [
82             [ qw/ 1 2 / ],
83             [ qw/ 3 4 / ],
84             ]
85             },
86             '1234',
87             'Nested arrays'
88             ],
89              
90             [
91             '',
92             {
93             bar => [
94             { id => 1 },
95             { id => 2 },
96             ]
97             },
98             '12',
99             'Each uses individual items as context'
100             ],
101              
102             [
103             '',
104             { foo => { bar => { baz => 1 } } },
105             '1', 'Dot notation references nested hashes'
106             ],
107              
108             [
109             'bar', { show => 1 },
110             'bar', 'If true keeps node'
111             ],
112              
113             [
114             'bar', { show => undef },
115             '', 'If false removes node'
116             ],
117              
118             [
119             'bar', { },
120             '', 'If false removes node'
121             ],
122              
123             [
124             'bar', { show => undef },
125             'bar', 'If not false keeps node'
126             ],
127              
128             [
129             'bar', { show => 1 },
130             '', 'If not true removes node'
131             ],
132              
133             [
134             '',
135             {
136             show => 1,
137             bar => [ 1, 2, 3 ],
138             },
139             '123',
140             'If + each + this all on one tag works'
141             ],
142              
143             [
144             '',
145             {
146             list => [ 1, 2 ],
147             num => 3,
148             },
149             '123',
150             'XML order retained when using varying types',
151             ],
152             [
153             '',
154             {
155             list => [ 0, 1 ],
156             num => 0,
157             },
158             '010',
159             'Number 0 is a valid value and passes if conditionals',
160             ],
161             [
162             '',{ num => 4 },
163             '4',
164             'Preserve comments'
165             ]
166             ];
167              
168 1         6 foreach my $t (@$tests) {
169 25         7731 my ($source_xml, $data, $output, $msg) = @$t;
170 25         82 is(XML::BindData->bind($source_xml, $data), $output, $msg);
171             }
172              
173 1         328 done_testing;