test attribute manglers
Matt S Trout [Sat, 6 Feb 2010 18:39:27 +0000 (18:39 +0000)]
t/actions.t

index 7333379..8e315d5 100644 (file)
@@ -109,4 +109,51 @@ is(
   </div>',
   '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"//;
+
+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'
+);
+
 done_testing;