From: Jakub Narebski Date: Mon, 10 Jan 2011 13:35:06 +0000 (+0100) Subject: Add test for 'flush_before' option X-Git-Tag: release_0.009004~9^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8af6dead371dda2793a0649592cfa0dcf905e5bc;p=catagits%2FHTML-Zoom.git Add test for 'flush_before' option 'flush_before' is actually option to ->collect() filter, which underlies the ->replace() and ->repeat() filters. Working version of example code from HTML::Zoom manpage (search for 'flush_before') is used in this test. --- diff --git a/t/flush.t b/t/flush.t new file mode 100644 index 0000000..bf60b64 --- /dev/null +++ b/t/flush.t @@ -0,0 +1,52 @@ +use strict; +use warnings FATAL => 'all'; + +use HTML::Zoom; +use HTML::Zoom::CodeStream; + +use Test::More; + + +# turns iterator into stream +sub code_stream (&) { + my $code = shift; + return sub { + HTML::Zoom::CodeStream->new({ + code => $code, + }); + } +} + +my $tmpl = <<'TMPL'; + +
+
+
+ +TMPL + +my $zoom = HTML::Zoom->from_html($tmpl); +my @list = qw(foo bar baz); + +foreach my $flush (0..1) { + + # from HTML::Zoom manpage, slightly modified + my $z2 = $zoom->select('.item')->repeat(code_stream { + if (my $name = shift @list) { + return sub { $_->select('.item-name')->replace_content($name) } + } else { + return + } + }, { flush_before => $flush }); + + my $fh = $z2->to_fh; + my $lineno = 0; + while (my $chunk = $fh->getline) { + $lineno++; + # debugging here + } + + cmp_ok($lineno, '==', 1+$flush, "flush_before => $flush is $lineno chunks"); +} + +done_testing;