Fix ->repeat with iterator, make t/repeat.t pass (formerly t/todo-repeat.t)
[catagits/HTML-Zoom.git] / t / flush.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use HTML::Zoom;
5 use Test::More;
6
7 my $tmpl = <<'TMPL';
8 <body>
9   <div class="item">
10     <div class="item-name"></div>
11   </div>
12 </body>
13 TMPL
14
15 my $zoom = HTML::Zoom->from_html($tmpl);
16 my @list = qw(foo bar baz);
17
18 foreach my $flush (0..1) {
19
20   # from HTML::Zoom manpage, slightly modified
21   my $z2 = $zoom->select('.item')->repeat(sub {
22     if (my $name = shift @list) {
23       return sub { $_->select('.item-name')->replace_content($name) }
24     } else {
25       return
26     }
27   }, { flush_before => $flush });
28
29   my $fh = $z2->to_fh;
30   my $lineno = 0;
31   while (my $chunk = $fh->getline) {
32     $lineno++;
33     # debugging here
34   }
35
36   cmp_ok($lineno, '==', 1+$flush, "flush_before => $flush is $lineno chunks");
37 }
38
39 done_testing;