From: Matt S Trout Date: Fri, 5 Feb 2010 21:09:54 +0000 (+0000) Subject: test collect in isolation X-Git-Tag: release_0.009004~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c86c0ce201e10213574d57b6339aa6a9883135fa;hp=cac9d0a57eb15ed103010151543d25cf27f3b157;p=catagits%2FHTML-Zoom.git test collect in isolation --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index b82a85c..7f9b7b6 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -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 before end of source"; diff --git a/lib/HTML/Zoom/Producer/BuiltIn.pm b/lib/HTML/Zoom/Producer/BuiltIn.pm index 3e4767f..fb869ee 100644 --- a/lib/HTML/Zoom/Producer/BuiltIn.pm +++ b/lib/HTML/Zoom/Producer/BuiltIn.pm @@ -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 diff --git a/t/actions.t b/t/actions.t index 80a909a..7333379 100644 --- a/t/actions.t +++ b/t/actions.t @@ -89,4 +89,24 @@ is( 'replace ok' ); +my @ev; + +is( + run_for { $_->collect({ into => \@ev }) }, + ' + + +', + 'collect removes without passthrough' +); + +is( + HTML::Zoom::Producer::BuiltIn->html_from_events(\@ev), + '
+ Bob + Builder +
+
', + 'collect collected right events' +); done_testing;