Add test for 'flush_before' option
[catagits/HTML-Zoom.git] / t / actions.t
index d9b883a..584ec36 100644 (file)
@@ -18,9 +18,9 @@ my $tmpl = <<END;
 </body>
 END
 
-sub src_stream { HTML::Zoom::Parser::BuiltIn->html_to_stream($tmpl); }
+sub src_stream { HTML::Zoom::Parser::BuiltIn->new->html_to_stream($tmpl); }
 
-sub html_sink { HTML::Zoom::Producer::BuiltIn->html_from_stream($_[0]) }
+sub html_sink { HTML::Zoom::Producer::BuiltIn->new->html_from_stream($_[0]) }
 
 my $fb = HTML::Zoom::FilterBuilder->new;
 
@@ -67,7 +67,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main foo"/;
 
 is(
-  run_for { $_->add_attribute({ name => 'class', value => 'foo' }) },
+  run_for { $_->add_to_attribute({ name => 'class', value => 'foo' }) },
   $expect,
   'add attribute on existing attribute'
 );
@@ -75,7 +75,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
 
 is(
-  run_for { $_->add_attribute({ name => 'foo', value => 'bar' }) },
+  run_for { $_->add_to_attribute({ name => 'foo', value => 'bar' }) },
   $expect,
   'add attribute on non existing attribute'
 );
@@ -262,4 +262,76 @@ is(
   'repeat_content ok'
 );
 
+is(
+  run_for {
+    my @between;
+    $_->repeat_content(
+      [
+        sub {
+          HTML::Zoom::ArrayStream->new({ array => [
+            (filter
+              filter($_ => '.name' => $r_content->('mst'))
+              => '.career' => $r_content->('Chainsaw Wielder')),
+            HTML::Zoom::ArrayStream->new({ array => \@between })
+          ] })->flatten
+        },
+        sub {
+          filter
+            filter($_ => '.name' => $r_content->('mdk'))
+            => '.career' => $r_content->('Adminion')
+        },
+      ],
+      { filter => sub {
+          filter $_[0] => 'hr' => sub { $_->collect({ into => \@between }) }
+        }
+      }
+    )
+  },
+  q{<body>
+  <div class="main">
+    <span class="hilight name">mst</span>
+    <span class="career">Chainsaw Wielder</span>
+    <hr />
+    <span class="hilight name">mdk</span>
+    <span class="career">Adminion</span>
+    
+  </div>
+</body>
+},
+  'repeat_content with filter ok'
+);
+
+is(
+  run_for {
+    my @between;
+    $_->repeat_content(
+      [
+        sub {
+          filter
+            filter($_ => '.name' => $r_content->('mst'))
+            => '.career' => $r_content->('Chainsaw Wielder')
+        },
+        sub {
+          filter
+            filter($_ => '.name' => $r_content->('mdk'))
+            => '.career' => $r_content->('Adminion')
+        },
+      ],
+      { repeat_between => 'hr' }
+    )
+  },
+  q{<body>
+  <div class="main">
+    <span class="hilight name">mst</span>
+    <span class="career">Chainsaw Wielder</span>
+    <hr />
+    <span class="hilight name">mdk</span>
+    <span class="career">Adminion</span>
+    
+  </div>
+</body>
+},
+  'repeat_content using repeat_between ok'
+);
+
 done_testing;