/
04-nest.t
82 lines (70 loc) · 1.31 KB
/
04-nest.t
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
use v6;
#BEGIN { @*INC.unshift: './lib'; }
use Test;
use Template6;
plan 2;
my $t6 = Template6.new;
$t6.add-path: 't/templates';
my $wanted = "<html>
<head>
<title>Nesting Test</title>
</head>
<body>
<table>
<tr>
<th>User</th>
<th>Age</th>
<th>Job</th>
</tr>
<tr>
<td>Bob</td>
<td>27</td>
<td>CEO</td>
</tr>
<tr>
<td>Lisa</td>
<td>18</td>
<td>Marketing</td>
</tr>
<tr>
<td>Melissa</td>
<td>31</td>
<td>VP Sales</td>
</tr>
</table>
</body>
</html>
";
my @users =
{
:name<Bob>,
:age(27),
:job<CEO>,
},
{
:name<Lisa>,
:age(18),
:job<Marketing>,
},
{
:name<Melissa>,
:age(31),
:job<VP Sales>,
};
is $t6.process('simple-nest', :users(@users)), $wanted, 'Nested data with array of hashes';
class CompanyUser {
has $.name;
has $.job;
has $.birthday;
method age {
## A real application would use today, but our test is hard coded.
#my $now = Date.today;
my $now = Date.new('2012-07-17');
return (($now - $.birthday) / 365).Int;
}
}
@users =
CompanyUser.new(:name<Bob>, :job<CEO>, :birthday(Date.new('1985-07-13'))),
CompanyUser.new(:name<Lisa>, :job<Marketing>, :birthday(Date.new('1994-05-11'))),
CompanyUser.new(:name<Melissa>, :job<VP Sales>, :birthday(Date.new('1981-03-21')));
is $t6.process('simple-nest', :users(@users)), $wanted, 'Nested data with array of objects';