ignore if attr doesn't exist.
[catagits/HTML-Zoom.git] / t / actions.t
index 6e1541b..7f23cd4 100644 (file)
@@ -50,15 +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"/;
+
+is(
+  run_for { $_->set_attr({ name => 'class', value => 'foo' }) },
+  $expect,
+  'set attribute on existing attribute (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'
 );
@@ -66,15 +74,31 @@ 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'
 );
 
+($expect = $tmpl) =~ s/class="main"/class="main foo"/;
+
+is(
+  run_for { $_->add_class('foo') },
+  $expect,
+  'add attribute on existing attribute (shorthand)'
+);
+
+($expect = $tmpl) =~ s/class="main"/class="main" id="foo"/;
+
+is(
+  run_for { $_->set_id('foo') },
+  $expect,
+  'set_id (shorthand)'
+);
+
 ($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'
 );
@@ -93,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(