test collect in isolation
Matt S Trout [Fri, 5 Feb 2010 21:09:54 +0000 (21:09 +0000)]
lib/HTML/Zoom/FilterBuilder.pm
lib/HTML/Zoom/Producer/BuiltIn.pm
t/actions.t

index b82a85c..7f9b7b6 100644 (file)
@@ -138,12 +138,12 @@ sub collect {
       while (my ($evt) = $stream->next) {
         $depth++ if ($evt->{type} eq 'OPEN');
         $depth-- if ($evt->{type} eq 'CLOSE');
+        push(@$into, $evt) if $into;
         unless ($depth) {
           undef $stream;
           return $evt if $passthrough;
           return;
         }
-        push(@$into, $evt) if $into;
         return $evt if $passthrough;
       }
       die "Never saw closing </${name}> before end of source";
index 3e4767f..fb869ee 100644 (file)
@@ -10,6 +10,11 @@ sub html_from_stream {
   return $html;
 }
 
+sub html_from_events {
+  my ($class, $events) = @_;
+  join '', map $class->_event_to_html($_), @$events;
+}
+
 sub _event_to_html {
   my ($self, $evt) = @_;
   # big expression
index 80a909a..7333379 100644 (file)
@@ -89,4 +89,24 @@ is(
   'replace ok'
 );
 
+my @ev;
+
+is(
+  run_for { $_->collect({ into => \@ev }) },
+  '<body>
+  
+</body>
+',
+  'collect removes without passthrough'
+);
+
+is(
+  HTML::Zoom::Producer::BuiltIn->html_from_events(\@ev),
+  '<div class="main">
+    <span class="hilight name">Bob</span>
+    <span class="career">Builder</span>
+    <hr />
+  </div>',
+  'collect collected right events'
+);
 done_testing;