test replace inside
Matt S Trout [Sat, 6 Feb 2010 20:23:44 +0000 (20:23 +0000)]
lib/HTML/Zoom/FilterBuilder.pm
t/actions.t

index e06d570..bccc856 100644 (file)
@@ -128,18 +128,25 @@ sub append_inside {
 }
 
 sub replace {
-  my ($self, $events) = @_;
+  my ($self, $events, $options) = @_;
   sub {
     my ($evt, $stream) = @_;
     my $emit = $self->_stream_from_array(@$events);
-    my $coll = $self->collect->(@_);
-    return $coll ? $self->_stream_concat($emit, $coll) : $emit;
+    my $coll = $self->collect($options)->(@_);
+    return
+      ($coll
+        ? (ref $coll eq 'ARRAY'
+            ? [ $coll->[0], $self->_stream_concat($emit, $coll->[1]) ]
+            : $self->_stream_concat($emit, $coll)
+          )
+        : $emit
+      );
   };
 }
 
 sub collect {
-  my ($self, $attrs) = @_;
-  my ($into, $passthrough, $inside) = @{$attrs}{qw(into passthrough inside)};
+  my ($self, $options) = @_;
+  my ($into, $passthrough, $inside) = @{$options}{qw(into passthrough inside)};
   sub {
     my ($evt, $stream) = @_;
     push(@$into, $evt) if $into && !$inside;
index 625c48e..f369b13 100644 (file)
@@ -179,4 +179,13 @@ is(
   'collect w/inside collects correctly'
 );
 
+is(
+  run_for { $_->replace($ohai, { inside => 1 }) },
+  '<body>
+  <div class="main">O HAI</div>
+</body>
+',
+  'replace w/inside'
+);
+
 done_testing;