File: 01-sanity.t

package info (click to toggle)
libtemplate-plugin-datetime-perl 0.06002-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 1,369; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,054 bytes parent folder | download | duplicates (3)
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
#!perl
use strict;
use Test::More (tests => 9);
BEGIN
{
    use_ok("Template::Plugin::DateTime");
}

use Template;

my $dt;
my $output;

my $tt = Template->new({ POST_CHOMP => 1 });
my $template = <<EOM;
[% USE date = DateTime(year => 2000, month => 1, day => 1 ) %]
[% date.datetime %]
EOM

$tt->process(\$template, undef, \$output);
$dt = DateTime->new(year => 2000, month => 1, day => 1);
is($output, $dt->datetime);

$output = '';
$template = <<EOM;
[% USE date = DateTime(now = 1) %]
[% date.datetime %]
EOM
$tt->process(\$template, undef, \$output);
$dt = DateTime->now(); # time will be different, but that's okay.
is($output, $dt->datetime);

$output = '';
$template = <<EOM;
[% USE date = DateTime(today = 1) %]
[% date.datetime %]
EOM
$tt->process(\$template, undef, \$output);
$dt = DateTime->today(); 
is($output, $dt->datetime);

$output = '';
$template = <<EOM;
[% USE date = DateTime(last_day_of_month = 1, year = 2004, month = 2) %]
[% date.datetime %]
EOM
$tt->process(\$template, undef, \$output);
$dt = DateTime->last_day_of_month(year => 2004, month => 2);
is($output, $dt->datetime);

$output = '';
$template = <<EOM;
[% USE date1 = DateTime(now = 1) %]
[% USE date2 = DateTime(from_object = date1) %]
[% IF date1 == date2 %]
ok
[% ELSE %]
nok
[% END %]
EOM
$tt->process(\$template, undef, \$output);
like($output, qr(^ok$));

$output = '';
$template = <<EOM;
[% USE date1 = DateTime(now = 1) %]
[% USE date2 = DateTime(from_epoch = date1.epoch) %]
[% IF date1 == date2 %]
ok
[% ELSE %]
nok
[% END %]
EOM
$tt->process(\$template, undef, \$output);
like($output, qr(^ok$));

$output = '';
$template = <<EOM;
[% USE date = DateTime(year => 2005, month => 7, day => 13, time_zone => 'Asia/Tokyo') %]
[% date.datetime %]
EOM
$tt->process(\$template, undef, \$output);
is($output, "2005-07-13T00:00:00");

$output = '';
$template = <<EOM;
[% USE date = DateTime(from_string => '2008-05-30 10:00:00', pattern => '%Y-%m-%d %H:%M:%S') %]
[% date.datetime %]
EOM
$tt->process(\$template, undef, \$output);
is($output, "2008-05-30T10:00:00");