X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frepeat_bugfixes.t;fp=t%2Frepeat_bugfixes.t;h=4684b47179e4c34d46b1e3316ff46d4dd4802534;hb=94a3ddd9ea6e8c859f01407cc17c7042ccf34ba0;hp=0000000000000000000000000000000000000000;hpb=8ee07fa4a7e0efc9155aae8b0e36e731295deeda;p=catagits%2FHTML-Zoom.git diff --git a/t/repeat_bugfixes.t b/t/repeat_bugfixes.t new file mode 100644 index 0000000..4684b47 --- /dev/null +++ b/t/repeat_bugfixes.t @@ -0,0 +1,141 @@ +use strict; +use warnings FATAL => 'all'; + +use HTML::Zoom; +use Test::More; + +ok my $zoom = HTML::Zoom->from_html(< + + Hi! + + +

Test

+
+

Some Stuff

+

More Stuff

+

Even More Stuff

+
    +
  1. First
  2. +
  3. Stuff A
  4. +
  5. Stuff B
  6. +
  7. Stuff C
  8. +
  9. Last
  10. +
+ +

Even More stuff

+

Some Stuff

+
+
+

Sub Item

+
+ + + + + + +HTML + +## Stub for testing the fill method to be + +ok my $title = sub { + my ($z, $content) = @_; + $z = $z->select('title')->replace_content($content); + return $z; +}; + +{ + ok my $z = HTML::Zoom + ->from_html(q[]) + ->select('ul') + ->repeat_content( + [ + sub { $_->select('li')->replace_content('Real Life1') }, + sub { $_->select('li')->replace_content('Real Life2') }, + sub { $_->select('li')->replace_content('Real Life3') }, + ], + ) + ->to_html; + + is $z, '', + 'Got correct from repeat_content'; +} + +{ + ok my $z = HTML::Zoom + ->from_html(q[]) + ->select('ul') + ->repeat_content([ + map { my $i = $_; +sub {$_->select('li')->replace_content("Real Life$i")} } (1,2,3) + ]) + ->to_html; + + is $z, '', + 'Got correct from repeat_content'; +} + + +use HTML::Zoom::CodeStream; +sub code_stream (&) { + my $code = shift; + return sub { + HTML::Zoom::CodeStream->new({ + code => $code, + }); + } +} + +{ + my @list = qw(foo bar baz); + ok my $z = HTML::Zoom + ->from_html(q[]) + ->select('ul') + ->repeat_content(code_stream { + if (my $name = shift @list) { + return sub { $_->select('li')->replace_content($name) }; + } else { + return + } + }) + ->to_html; + + is $z, '', + 'Got correct from repeat_content'; +} + +{ + my @list = qw(foo bar baz); + ok my $z = HTML::Zoom + ->from_html(q[]) + ->select('ul') + ->repeat_content(sub { + HTML::Zoom::CodeStream->new({ + code => sub { + if (my $name = shift @list) { + return sub { $_->select('li')->replace_content($name) }; + } else { + return + } + } + }); + }) + ->to_html; + + is $z, '', + 'Got correct from repeat_content'; +} + +done_testing;