commit tests, uncomment codez
Arthur Axel 'fREW' Schmidt [Fri, 16 Apr 2010 02:31:06 +0000 (21:31 -0500)]
lib/HTML/Zoom/SelectorParser.pm
t/selectors.t [new file with mode: 0644]

index 37e7ec1..2a737ef 100644 (file)
@@ -137,7 +137,7 @@ sub parse_selector {
     PARSE: { do {
       push(@sub, $self->_raw_parse_simple_selector($_));
       last PARSE if (pos == length);
-      #/\G\s*,\s*/gc or confess "Selectors not comma separated";
+      /\G\s*,\s*/gc or confess "Selectors not comma separated";
     } until (pos == length) };
     return $sub[0] if (@sub == 1);
     return sub {
diff --git a/t/selectors.t b/t/selectors.t
new file mode 100644 (file)
index 0000000..2ce3c48
--- /dev/null
@@ -0,0 +1,71 @@
+use strict;
+#use warnings FATAL => 'all';
+use Test::More;
+
+use HTML::Zoom;
+
+# el#id
+is( HTML::Zoom->from_html('<div id="yo"></div>')
+   ->select('div#yo')
+      ->replace_content('grg')
+   ->to_html,
+   '<div id="yo">grg</div>',
+   'E#id works' );
+
+# el.class1
+is( HTML::Zoom->from_html('<div class="yo"></div>')
+   ->select('div.yo')
+      ->replace_content('grg')
+   ->to_html,
+   '<div class="yo">grg</div>',
+   'E.class works' );
+
+# el[attr]
+is( HTML::Zoom->from_html('<div frew="yo"></div>')
+   ->select('div[frew]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div frew="yo">grg</div>',
+   'E[attr] works' );
+
+# el[attr="foo"]
+is( HTML::Zoom->from_html('<div frew="yo"></div>')
+   ->select('div[frew="yo"]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div frew="yo">grg</div>',
+   'E[attr="val"] works' );
+
+# el[attr*="foo"]
+is( HTML::Zoom->from_html('<div f="frew goog"></div>')
+   ->select('div[f*="oo"]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div f="frew goog">grg</div>',
+   'E[attr*="val"] works' );
+
+# el[attr^="foo"]
+is( HTML::Zoom->from_html('<div f="foobar"></div>')
+   ->select('div[f^="foo"]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div f="foobar">grg</div>',
+   'E[attr^="val"] works' );
+
+# el[attr$="foo"]
+is( HTML::Zoom->from_html('<div f="foobar"></div>')
+   ->select('div[f$="bar"]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div f="foobar">grg</div>',
+   'E[attr$="val"] works' );
+
+# el[attr*="foo"]
+is( HTML::Zoom->from_html('<div f="foo bar"></div>')
+   ->select('div[f*="bar"]')
+      ->replace_content('grg')
+   ->to_html,
+   '<div f="foo bar">grg</div>',
+   'E[attr*="val"] works' );
+
+done_testing;