X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Factions.t;fp=t%2Factions.t;h=6e1541ba9181ee9a858828da7c11ae6baf21ce4e;hb=5cac799ef22c33ef914b2cf9ba1c66a2a1b403e1;hp=c89a5b8c44d7457654c50e93c11e932f891a0f41;hpb=c2d3257f34803842cf44d9ccb0d086aaa3b2dd5e;p=catagits%2FHTML-Zoom.git diff --git a/t/actions.t b/t/actions.t index c89a5b8..6e1541b 100644 --- a/t/actions.t +++ b/t/actions.t @@ -93,6 +93,64 @@ is( 'remove attribute on non existing attribute' ); +($expect = $tmpl) =~ s/ class="main"//; + +is( + run_for { + $_->transform_attribute({ + name => 'class', + code => sub { + my $a = shift; + return if $a eq 'main'; + return $a; + }, + }) + }, + $expect, + 'transform_attribute deletes the attr if code returns undef', + ); + +($expect = $tmpl) =~ s/ class="main"/ class="moan"/; + +is( + run_for { + $_->transform_attribute({ + name => 'class', + code => sub { + ( my $b = shift ) =~ s/main/moan/; + $b + }, + }) + }, + $expect, + 'transform_attribute transforms something', + ); + +($expect = $tmpl) =~ s/ class="main"/ class="main" noggin="zonk"/; + +is( + run_for { + $_->transform_attribute({ + name => 'noggin', + code => sub { 'zonk' }, + }) + }, + $expect, + 'transform_attribute adds attribute if not there before', + ); + +is( + run_for { + $_->transform_attribute({ + name => 'noggin', + code => sub { }, + }) + }, + $tmpl, + 'transform_attribute on nonexistent att does not add it if code returns undef', + ); + + ($expect = $tmpl) =~ s/(?= 'TEXT', raw => 'O HAI' } ];