)
}
-(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' } ];
'replace ok'
);
-my @ev;
+@ev = ();
is(
run_for { $_->collect({ into => \@ev }) },
</div>',
'collect collected right events'
);
+
+@ev = ();
+
+is(
+ run_for { $_->collect({ into => \@ev, inside => 1 }) },
+ '<body>
+ <div class="main"></div>
+</body>
+',
+ 'collect w/inside removes correctly'
+);
+
+is(
+ 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'
+);
+
+is(
+ run_for { $_->replace($ohai, { inside => 1 }) },
+ '<body>
+ <div class="main">O HAI</div>
+</body>
+',
+ 'replace w/inside'
+);
+
done_testing;