getting things synced up for a release
[catagits/HTML-Zoom.git] / t / actions.t
index c2df1df..d1dcc54 100644 (file)
@@ -9,7 +9,7 @@ use HTML::Zoom::FilterStream;
 
 my $tmpl = <<END;
 <body>
-  <div class="main">
+  <div name="cow" class="main">
     <span class="hilight name">Bob</span>
     <span class="career">Builder</span>
     <hr />
@@ -50,23 +50,23 @@ my ($expect, @ev);
 ($expect = $tmpl) =~ s/class="main"/class="foo"/;
 
 is(
-  run_for { $_->set_attribute({ name => 'class', value => 'foo' }) },
+  run_for { $_->set_attribute( 'class' => 'foo' ) },
   $expect,
   'set attribute on existing attribute'
 );
 
-($expect = $tmpl) =~ s/class="main"/class="foo"/;
+($expect = $tmpl) =~ s/name="cow" class="main"/name="bar" class="foo"/;
 
 is(
-  run_for { $_->set_attr({ name => 'class', value => 'foo' }) },
+  run_for { $_->set_attr({ 'class' => 'foo', 'name' => 'bar'}) },
   $expect,
-  'set attribute on existing attribute (shorthand)'
+  'set attributes using hashref form (shorthand)'
 );
 
 ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
 
 is(
-  run_for { $_->set_attribute({ name => 'foo', value => 'bar' }) },
+  run_for { $_->set_attribute( 'foo' => 'bar' ) },
   $expect,
   'set attribute on non existing attribute'
 );
@@ -74,7 +74,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main foo"/;
 
 is(
-  run_for { $_->add_to_attribute({ name => 'class', value => 'foo' }) },
+  run_for { $_->add_to_attribute( 'class' => 'foo' ) },
   $expect,
   'add attribute on existing attribute'
 );
@@ -98,7 +98,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
 
 is(
-  run_for { $_->add_to_attribute({ name => 'foo', value => 'bar' }) },
+  run_for { $_->add_to_attribute( 'foo' => 'bar' ) },
   $expect,
   'add attribute on non existing attribute'
 );
@@ -117,6 +117,28 @@ is(
   'remove attribute on non existing attribute'
 );
 
+($expect = $tmpl) =~ s/class="main"/class=""/;
+
+is(
+  run_for { $_->remove_from_attribute({ class => 'main' }) },
+  $expect,
+  'remove name from attribute'
+);
+
+is(
+  run_for { $_->remove_from_attribute({ madeup => 'main' }) },
+  $tmpl,
+  'remove name from non existing attribute (ignored)'
+);
+
+($expect = $tmpl) =~ s/class="main"/class=""/;
+
+is(
+  run_for { $_->remove_class( 'main' ) },
+  $expect,
+  'remove_class'
+);
+
 ($expect = $tmpl) =~ s/ class="main"//;
 
 is(
@@ -231,7 +253,7 @@ is(
 
 is(
   HTML::Zoom::Producer::BuiltIn->html_from_events(\@ev),
-  '<div class="main">
+  '<div name="cow" class="main">
     <span class="hilight name">Bob</span>
     <span class="career">Builder</span>
     <hr />
@@ -244,7 +266,7 @@ is(
 is(
   run_for { $_->collect({ into => \@ev, content => 1 }) },
   '<body>
-  <div class="main"></div>
+  <div name="cow" class="main"></div>
 </body>
 ',
   'collect w/content removes correctly'
@@ -263,7 +285,7 @@ is(
 is(
   run_for { $_->replace($ohai, { content => 1 }) },
   '<body>
-  <div class="main">O HAI</div>
+  <div name="cow" class="main">O HAI</div>
 </body>
 ',
   'replace w/content'
@@ -297,11 +319,11 @@ is(
     )
   },
   q{<body>
-  <div class="main">
+  <div name="cow" class="main">
     <span class="hilight name">mst</span>
     <span class="career">Chainsaw Wielder</span>
     <hr />
-  </div><div class="main">
+  </div><div name="cow" class="main">
     <span class="hilight name">mdk</span>
     <span class="career">Adminion</span>
     <hr />
@@ -329,7 +351,7 @@ is(
     )
   },
   q{<body>
-  <div class="main">
+  <div name="cow" class="main">
     <span class="hilight name">mst</span>
     <span class="career">Chainsaw Wielder</span>
     <hr />
@@ -369,7 +391,7 @@ is(
     )
   },
   q{<body>
-  <div class="main">
+  <div name="cow" class="main">
     <span class="hilight name">mst</span>
     <span class="career">Chainsaw Wielder</span>
     <hr />
@@ -402,7 +424,7 @@ is(
     )
   },
   q{<body>
-  <div class="main">
+  <div name="cow" class="main">
     <span class="hilight name">mst</span>
     <span class="career">Chainsaw Wielder</span>
     <hr />