3 use vars qw( @ISA @EXPORT $Dat_Dir );
9 use Cwd qw( abs_path );
28 $Bulk_File $Head_File $Odd_File $Woy_File $I8N_File $Narrow_File
30 check_bulk_with_datetool
31 check_odd_with_datetool
32 check_woy_with_datetool
47 use HTML::CalendarMonth;
48 use HTML::CalendarMonth::DateTool;
51 my($vol, $dir, $file) = File::Spec->splitpath(abs_path(__FILE__));
52 $dir = File::Spec->catdir($dir, 'dat');
53 $Dat_Dir = File::Spec->catpath($vol, $dir, '');
56 $Bulk_File = File::Spec->catdir($Dat_Dir, 'bulk.dat');
57 $Head_File = File::Spec->catdir($Dat_Dir, 'head.dat');
58 $Odd_File = File::Spec->catdir($Dat_Dir, 'odd.dat');
59 $Woy_File = File::Spec->catdir($Dat_Dir, 'woy.dat');
60 $I8N_File = File::Spec->catdir($Dat_Dir, 'i8n.dat');
61 $Narrow_File = File::Spec->catdir($Dat_Dir, 'narrow.dat');
63 my(@Bulk, @Head, @Odd, @Woy, @I8N, @Nar);
67 my $cal = shift || [];
69 return unless open(F, '<', $f);
72 my($d, $wb, @other) = split(/\s+/, $h);
73 my($y, $m) = split(/\//, $d);
76 push(@$cal, [$d, $y, $m, $wb, \@other, clean($c)]);
81 _load_file($Bulk_File, \@Bulk );
82 _load_file($Head_File, \@Head );
83 _load_file($Odd_File, \@Odd );
84 _load_file($Woy_File, \@Woy );
85 _load_file($I8N_File, \@I8N );
86 _load_file($Narrow_File, \@Nar);
88 sub bulk_count { scalar @Bulk }
89 sub head_count { scalar @Head }
90 sub odd_count { scalar @Odd }
91 sub woy_count { scalar @Woy }
92 sub i8n_count { scalar @I8N }
93 sub narrow_count { scalar @Nar }
96 my($month, $year) = (localtime(time))[4,5];
100 my $today = sprintf("%d/%02d", $year, $month);
101 my $year_from_now = sprintf("%d/%02d", $year+1, $month);
104 @Bulk = grep { $_ ge $today && $_->[0] le $year_from_now } @Bulk;
109 my $str = shift || Carp::confess "string required";
110 $str =~ s/^\s*//; $str =~ s/\s*$//;
111 # guard against HTML::Tree starting to quote numeric attrs as of
113 $str =~ s/\"(\d+)\"/$1/g;
118 my $datetool = shift;
119 my $module = HTML::CalendarMonth::DateTool->_toolmap($datetool);
120 ok($module, "toolmap($datetool) : $module");
124 sub check_bulk_with_datetool {
125 my $datetool = shift;
128 my($d, $y, $m, $wb, $other, $tc) = @$_;
129 my $c = HTML::CalendarMonth->new(
133 datetool => $datetool,
135 @days = $c->dayheaders unless @days;
136 my $day1 = $days[$wb - 1];
137 my $method = $c->_caltool->_name;
138 $method = "auto-select ($method)" unless $datetool;
140 "(%d/%02d %s 1st day) using %s",
141 $y, $m, $day1, $method
143 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
147 sub check_head_with_datetool {
148 my $datetool = shift;
151 my($d, $y, $m, $wb, $other, $tc) = @$_;
152 my($hm, $hy, $hd, $hw) = @$other;
153 my $c = HTML::CalendarMonth->new(
161 datetool => $datetool,
163 my $method = $c->_caltool->_name;
164 $method = "auto-select ($method)" unless $datetool;
166 "(%d/%02d hm:%d hy:%d hd:%d hw:%d) using %s",
167 $y, $m, $hm, $hy, $hd, $hw, $method
169 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
173 sub check_odd_with_datetool {
174 my $datetool = shift;
177 my($d, $y, $m, $wb, $other, $tc) = @$_;
181 $c = HTML::CalendarMonth->new(
185 datetool => $datetool,
189 croak $@ unless $@ =~ /(no|in)\s*valid date tool/i;
190 skip("$datetool odd $y/$m", 1);
192 @days = $c->dayheaders unless @days;
193 my $day1 = $days[$wb - 1];
194 my $method = $c->_caltool->_name;
195 $method = "auto-select ($method)" unless $datetool;
197 "(%d/%02d %s 1st day) using %s",
198 $y, $m, $day1, $method
200 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
205 sub check_woy_with_datetool {
206 my $datetool = shift;
208 my($d, $y, $m, $wb, $other, $tc) = @$_;
209 my $c = HTML::CalendarMonth->new(
213 datetool => $datetool,
215 my $msg = sprintf("(%d/%02d week of year) using %s", $y, $m, $datetool);
216 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
222 my($d, $y, $m, $id, $other, $tc) = @$_;
223 my $c = HTML::CalendarMonth->new(
228 my $name = $c->loc->loc->name;
230 "(%d/%02d i8n) %s (wb:%d) using auto-detect",
231 $y, $m, $name, $c->week_begin
233 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
240 my($d, $y, $m, $wb, $other, $tc) = @$_;
241 my $c = HTML::CalendarMonth->new(
247 @days = $c->dayheaders unless @days;
248 my $day1 = $days[$wb - 1];
250 "(%d/%02d %s/%s 1st day) narrow/alias using auto-detect",
251 $y, $m, $day1, $c->item_alias($day1)
253 cmp_ok(clean($c->as_HTML), 'eq', $tc, $msg);
258 my($l1, $str1, $l2, $str2) = @_;
260 open(DUMP, ">$DEBUG") or die "Could not dump to $DEBUG: $!\n";
261 print DUMP "<html><body><table><tr><td>$l1</td><td>$l2</td></tr><tr><td>\n";
262 print DUMP "$str1\n</td><td>\n";
263 print DUMP "$str2\n</td></tr></table></body></html>\n";
265 print STDERR "\nDumped tables to $DEBUG. Aborting test.\n";