add peek method to streams, implement 'inside' for collect
[catagits/HTML-Zoom.git] / t / actions.t
index 8e315d5..625c48e 100644 (file)
@@ -46,7 +46,55 @@ sub run_for (&;$) {
   )
 }
 
-(my $expect = $tmpl) =~ s/(?=<div)/O HAI/;
+my ($expect, @ev);
+
+($expect = $tmpl) =~ s/class="main"/class="foo"/;
+
+is(
+  run_for { $_->set_attribute({ name => 'class', value => 'foo' }) },
+  $expect,
+  'set attribute on existing attribute'
+);
+
+($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
+
+is(
+  run_for { $_->set_attribute({ name => 'foo', value => 'bar' }) },
+  $expect,
+  'set attribute on non existing attribute'
+);
+
+($expect = $tmpl) =~ s/class="main"/class="main foo"/;
+
+is(
+  run_for { $_->add_attribute({ name => 'class', value => 'foo' }) },
+  $expect,
+  'add attribute on existing attribute'
+);
+
+($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
+
+is(
+  run_for { $_->add_attribute({ name => 'foo', value => 'bar' }) },
+  $expect,
+  'add attribute on non existing attribute'
+);
+
+($expect = $tmpl) =~ s/ class="main"//;
+
+is(
+  run_for { $_->remove_attribute({ name => 'class' }) },
+  $expect,
+  'remove attribute on existing attribute'
+);
+
+is(
+  run_for { $_->remove_attribute({ name => 'foo' }) },
+  $tmpl,
+  'remove attribute on non existing attribute'
+);
+
+($expect = $tmpl) =~ s/(?=<div)/O HAI/;
 
 my $ohai = [ { type => 'TEXT', raw => 'O HAI' } ];
 
@@ -89,7 +137,7 @@ is(
   'replace ok'
 );
 
-my @ev;
+@ev = ();
 
 is(
   run_for { $_->collect({ into => \@ev }) },
@@ -110,50 +158,25 @@ is(
   'collect collected right events'
 );
 
-($expect = $tmpl) =~ s/class="main"/class="foo"/;
-
-is(
-  run_for { $_->set_attribute({ name => 'class', value => 'foo' }) },
-  $expect,
-  'set attribute on existing attribute'
-);
-
-($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
-
-is(
-  run_for { $_->set_attribute({ name => 'foo', value => 'bar' }) },
-  $expect,
-  'set attribute on non existing attribute'
-);
-
-($expect = $tmpl) =~ s/class="main"/class="main foo"/;
-
-is(
-  run_for { $_->add_attribute({ name => 'class', value => 'foo' }) },
-  $expect,
-  'add attribute on existing attribute'
-);
-
-($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
-
-is(
-  run_for { $_->add_attribute({ name => 'foo', value => 'bar' }) },
-  $expect,
-  'add attribute on non existing attribute'
-);
-
-($expect = $tmpl) =~ s/ class="main"//;
+@ev = ();
 
 is(
-  run_for { $_->remove_attribute({ name => 'class' }) },
-  $expect,
-  'remove attribute on existing attribute'
+  run_for { $_->collect({ into => \@ev, inside => 1 }) },
+  '<body>
+  <div class="main"></div>
+</body>
+',
+  'collect w/inside removes correctly'
 );
 
 is(
-  run_for { $_->remove_attribute({ name => 'foo' }) },
-  $tmpl,
-  'remove attribute on non existing attribute'
+  HTML::Zoom::Producer::BuiltIn->html_from_events(\@ev),
+  '
+    <span class="hilight name">Bob</span>
+    <span class="career">Builder</span>
+    <hr />
+  ',
+  'collect w/inside collects correctly'
 );
 
 done_testing;