Fix ->repeat with iterator, make t/repeat.t pass (formerly t/todo-repeat.t)
[catagits/HTML-Zoom.git] / t / flush.t
CommitLineData
8af6dead 1use strict;
2use warnings FATAL => 'all';
3
4use HTML::Zoom;
8af6dead 5use Test::More;
6
8af6dead 7my $tmpl = <<'TMPL';
8<body>
9 <div class="item">
10 <div class="item-name"></div>
11 </div>
12</body>
13TMPL
14
15my $zoom = HTML::Zoom->from_html($tmpl);
16my @list = qw(foo bar baz);
17
18foreach my $flush (0..1) {
19
20 # from HTML::Zoom manpage, slightly modified
15059df5 21 my $z2 = $zoom->select('.item')->repeat(sub {
8af6dead 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
39done_testing;