update version
[catagits/HTML-Zoom.git] / t / flush.t
CommitLineData
8af6dead 1use strict;
2use warnings FATAL => 'all';
3
4use HTML::Zoom;
5use HTML::Zoom::CodeStream;
6
7use Test::More;
8
9
10# turns iterator into stream
11sub code_stream (&) {
12 my $code = shift;
13 return sub {
14 HTML::Zoom::CodeStream->new({
15 code => $code,
16 });
17 }
18}
19
20my $tmpl = <<'TMPL';
21<body>
22 <div class="item">
23 <div class="item-name"></div>
24 </div>
25</body>
26TMPL
27
28my $zoom = HTML::Zoom->from_html($tmpl);
29my @list = qw(foo bar baz);
30
31foreach my $flush (0..1) {
32
33 # from HTML::Zoom manpage, slightly modified
34 my $z2 = $zoom->select('.item')->repeat(code_stream {
35 if (my $name = shift @list) {
36 return sub { $_->select('.item-name')->replace_content($name) }
37 } else {
38 return
39 }
40 }, { flush_before => $flush });
41
42 my $fh = $z2->to_fh;
43 my $lineno = 0;
44 while (my $chunk = $fh->getline) {
45 $lineno++;
46 # debugging here
47 }
48
49 cmp_ok($lineno, '==', 1+$flush, "flush_before => $flush is $lineno chunks");
50}
51
52done_testing;