line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Natural::Test; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
11743
|
use strict; |
|
21
|
|
|
|
|
73
|
|
|
21
|
|
|
|
|
658
|
|
4
|
21
|
|
|
21
|
|
152
|
use warnings; |
|
21
|
|
|
|
|
68
|
|
|
21
|
|
|
|
|
645
|
|
5
|
21
|
|
|
21
|
|
118
|
use base qw(Exporter); |
|
21
|
|
|
|
|
70
|
|
|
21
|
|
|
|
|
2381
|
|
6
|
21
|
|
|
21
|
|
1578
|
use boolean qw(true false); |
|
21
|
|
|
|
|
11841
|
|
|
21
|
|
|
|
|
123
|
|
7
|
21
|
|
|
21
|
|
1455
|
use constant truncated => true; |
|
21
|
|
|
|
|
58
|
|
|
21
|
|
|
|
|
97
|
|
8
|
21
|
|
|
21
|
|
1611
|
use constant unaltered => false; |
|
21
|
|
|
|
|
53
|
|
|
21
|
|
|
|
|
102
|
|
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
21
|
|
1299
|
use File::Find; |
|
21
|
|
|
|
|
48
|
|
|
21
|
|
|
|
|
1976
|
|
11
|
21
|
|
|
21
|
|
11446
|
use File::Spec::Functions qw(abs2rel); |
|
21
|
|
|
|
|
19410
|
|
|
21
|
|
|
|
|
1429
|
|
12
|
21
|
|
|
21
|
|
2057
|
use List::MoreUtils qw(any); |
|
21
|
|
|
|
|
45243
|
|
|
21
|
|
|
|
|
170
|
|
13
|
21
|
|
|
21
|
|
26008
|
use Module::Util qw(fs_path_to_module); |
|
21
|
|
|
|
|
38714
|
|
|
21
|
|
|
|
|
1388
|
|
14
|
21
|
|
|
21
|
|
10952
|
use Test::More; |
|
21
|
|
|
|
|
1555088
|
|
|
21
|
|
|
|
|
305
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK, %EXPORT_TAGS, %time, $case_strings, $time_entries); |
17
|
|
|
|
|
|
|
my @set; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = '0.13'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@set = qw(truncated unaltered %time $case_strings |
22
|
|
|
|
|
|
|
$time_entries _run_tests _result_string |
23
|
|
|
|
|
|
|
_result_string_hires _message); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
@EXPORT_OK = (qw(_find_modules _find_files), @set); |
26
|
|
|
|
|
|
|
%EXPORT_TAGS = ('set' => [ @set ]); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
%time = map { split /:/ } |
29
|
|
|
|
|
|
|
split /\n/, |
30
|
|
|
|
|
|
|
do { local $/ = '__END__'; |
31
|
|
|
|
|
|
|
local $_ = <DATA>; |
32
|
|
|
|
|
|
|
chomp; |
33
|
|
|
|
|
|
|
$_ }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$case_strings = sub { ($_[0], lc $_[0], uc $_[0]) }; |
36
|
|
|
|
|
|
|
$time_entries = sub |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my ($string, $result) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $subst = sub |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
my ($str, $res, $entries) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if ($str =~ /\{(?: |at)\}/) { |
45
|
|
|
|
|
|
|
my @strings; |
46
|
|
|
|
|
|
|
if ($str =~ /\{ \}/) { |
47
|
|
|
|
|
|
|
foreach my $space ('', ' ') { |
48
|
|
|
|
|
|
|
(my $str_new = $str) =~ s/\{ \}/$space/; |
49
|
|
|
|
|
|
|
push @strings, $str_new; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
if ($str =~ /\{at\}/) { |
53
|
|
|
|
|
|
|
@strings = ($str) unless @strings; |
54
|
|
|
|
|
|
|
my @strings_new; |
55
|
|
|
|
|
|
|
foreach my $string (@strings) { |
56
|
|
|
|
|
|
|
foreach my $at ('', ' at') { |
57
|
|
|
|
|
|
|
(my $str_new = $string) =~ s/ \{at\}/$at/; |
58
|
|
|
|
|
|
|
push @strings_new, $str_new; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
@strings = @strings_new; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
push @$entries, [ $_, $res ] foreach @strings; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
push @$entries, [ $str, $res ]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my @entries; |
71
|
|
|
|
|
|
|
if ($string =~ /\{(?:min_)?sec\}/) { |
72
|
|
|
|
|
|
|
my ($desc, @values); |
73
|
|
|
|
|
|
|
my $sec = sprintf '%02d', int rand(60); |
74
|
|
|
|
|
|
|
local $1; |
75
|
|
|
|
|
|
|
if ($string =~ /\{(min_sec)\}/) { |
76
|
|
|
|
|
|
|
@values = ( |
77
|
|
|
|
|
|
|
[ '', '00:00' ], # hour |
78
|
|
|
|
|
|
|
[ ':00', '00:00' ], # minute |
79
|
|
|
|
|
|
|
[ ":00:$sec", "00:$sec" ], # second |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
$desc = $1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif ($string =~ /\{(sec)\}/) { |
84
|
|
|
|
|
|
|
@values = ( |
85
|
|
|
|
|
|
|
[ '', '00' ], # minute |
86
|
|
|
|
|
|
|
[ ":$sec", $sec ], # second |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
$desc = $1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
my $is_aref = ref $result eq 'ARRAY'; |
91
|
|
|
|
|
|
|
foreach my $value (@values) { |
92
|
|
|
|
|
|
|
(my $str = $string) =~ s/\{$desc\}/$value->[0]/; |
93
|
|
|
|
|
|
|
(my $res = $is_aref ? $result->[0] : $result) =~ s/\{$desc\}/$value->[1]/; |
94
|
|
|
|
|
|
|
$subst->($str, $is_aref ? [ $res, $result->[1] ] : $res, \@entries); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
|
|
|
|
|
|
$subst->($string, $result, \@entries); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return @entries; |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _run_tests |
105
|
|
|
|
|
|
|
{ |
106
|
16
|
|
|
16
|
|
62874
|
my ($tests, $sets, $check) = @_; |
107
|
|
|
|
|
|
|
|
108
|
16
|
|
|
|
|
56
|
$tests *= 3; # case tests |
109
|
|
|
|
|
|
|
|
110
|
16
|
|
|
|
|
41
|
local $@; |
111
|
|
|
|
|
|
|
|
112
|
16
|
50
|
|
|
|
1069
|
if (eval "require Date::Calc") { |
113
|
16
|
|
|
|
|
136
|
plan tests => $tests * 2; |
114
|
16
|
|
|
|
|
20769
|
foreach my $set (@$sets) { |
115
|
27
|
|
|
|
|
234
|
$check->(@$set); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
0
|
|
|
|
|
0
|
plan tests => $tests; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
16
|
|
|
|
|
277
|
$DateTime::Format::Natural::Compat::Pure = true; |
123
|
|
|
|
|
|
|
|
124
|
16
|
|
|
|
|
109
|
foreach my $set (@$sets) { |
125
|
27
|
|
|
|
|
254
|
$check->(@$set); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $result_string = sub |
130
|
|
|
|
|
|
|
{ |
131
|
|
|
|
|
|
|
my ($dt, $fmt, $units) = @_; |
132
|
|
|
|
|
|
|
return sprintf($fmt, map $dt->$_, @$units); |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _result_string |
136
|
|
|
|
|
|
|
{ |
137
|
10767
|
|
|
10767
|
|
168214
|
return $result_string->(shift, |
138
|
|
|
|
|
|
|
'%02d.%02d.%4d %02d:%02d:%02d', |
139
|
|
|
|
|
|
|
[qw(day month year hour min sec)]); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _result_string_hires |
143
|
|
|
|
|
|
|
{ |
144
|
198
|
|
|
198
|
|
4826
|
return $result_string->(shift, |
145
|
|
|
|
|
|
|
'%02d.%02d.%4d %02d:%02d:%02d.%03d', |
146
|
|
|
|
|
|
|
[qw(day month year hour min sec millisecond)]); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _message |
150
|
|
|
|
|
|
|
{ |
151
|
9966
|
|
|
9966
|
|
289665
|
my ($msg) = @_; |
152
|
|
|
|
|
|
|
|
153
|
9966
|
100
|
|
|
|
24231
|
my $how = $DateTime::Format::Natural::Compat::Pure |
154
|
|
|
|
|
|
|
? '(using DateTime)' |
155
|
|
|
|
|
|
|
: '(using Date::Calc)'; |
156
|
|
|
|
|
|
|
|
157
|
9966
|
|
|
|
|
103770
|
return "$msg $how"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _find_modules |
161
|
|
|
|
|
|
|
{ |
162
|
1
|
|
|
1
|
|
2470
|
my ($lib, $modules, $exclude) = @_; |
163
|
1
|
|
|
|
|
4
|
_gather_data($lib, undef, $modules, $exclude); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _find_files |
167
|
|
|
|
|
|
|
{ |
168
|
0
|
|
|
0
|
|
0
|
my ($lib, $files, $exclude) = @_; |
169
|
0
|
|
|
|
|
0
|
_gather_data($lib, $files, undef, $exclude); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _gather_data |
173
|
|
|
|
|
|
|
{ |
174
|
1
|
|
|
1
|
|
2
|
my ($lib, $files, $modules, $exclude) = @_; |
175
|
|
|
|
|
|
|
|
176
|
1
|
|
|
|
|
5
|
my ($save_files, $save_modules) = map defined, ($files, $modules); |
177
|
1
|
|
|
|
|
6
|
my $ext = qr/\.pm$/; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
find(sub { |
180
|
21
|
100
|
|
21
|
|
753
|
return unless $_ =~ $ext; |
181
|
15
|
|
|
|
|
60
|
my $rel_path = abs2rel($File::Find::name, $lib); |
182
|
15
|
50
|
|
|
|
929
|
my $module = fs_path_to_module($rel_path) or return; |
183
|
15
|
50
|
|
|
|
829
|
return if any { $module =~ /${_}$/ } @$exclude; |
|
0
|
|
|
|
|
0
|
|
184
|
15
|
50
|
|
|
|
61
|
if ($save_files) { |
|
|
50
|
|
|
|
|
|
185
|
0
|
|
|
|
|
0
|
push @$files, $File::Find::name; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
elsif ($save_modules) { |
188
|
15
|
|
|
|
|
392
|
push @$modules, $module; |
189
|
|
|
|
|
|
|
} |
190
|
1
|
|
|
|
|
173
|
}, $lib); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
__DATA__ |
195
|
|
|
|
|
|
|
year:2006 |
196
|
|
|
|
|
|
|
month:11 |
197
|
|
|
|
|
|
|
day:24 |
198
|
|
|
|
|
|
|
hour:1 |
199
|
|
|
|
|
|
|
minute:13 |
200
|
|
|
|
|
|
|
second:8 |
201
|
|
|
|
|
|
|
nanosecond:0 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__END__ |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 NAME |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
DateTime::Format::Natural::Test - Common test routines/data |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 SYNOPSIS |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Please see the DateTime::Format::Natural documentation. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 DESCRIPTION |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The C<DateTime::Format::Natural::Test> class exports common test routines. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 SEE ALSO |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L<DateTime::Format::Natural> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Steven Schubiger <schubiger@cpan.org> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 LICENSE |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or |
228
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |