[gxml] Implemented CssSelectorParser E:last-child pseudo selector
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Implemented CssSelectorParser E:last-child pseudo selector
- Date: Fri, 8 Sep 2017 17:04:30 +0000 (UTC)
commit bdaad1a6e758457e13e5f0ef5b329dfabf999a0a
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Sep 8 09:27:27 2017 -0700
Implemented CssSelectorParser E:last-child pseudo selector
gxml/CssSelectorParser.vala | 9 ++++
test/CssSelectorTest.vala | 95 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 95 insertions(+), 9 deletions(-)
---
diff --git a/gxml/CssSelectorParser.vala b/gxml/CssSelectorParser.vala
index 7610d76..48f66f9 100644
--- a/gxml/CssSelectorParser.vala
+++ b/gxml/CssSelectorParser.vala
@@ -390,6 +390,15 @@ public class GXml.CssSelectorParser : GLib.Object {
if ((element as GNode).get_internal_node ()
== ((element.parent_node as
DomParentNode).first_element_child as GNode).get_internal_node ()) return true;
}
+ if (s.data.down () == "last-child") {
+ if (element.parent_node == null) return false;
+ if (!(element.parent_node is DomElement)) return false;
+ if (element is GomElement)
+ if (element == (element.parent_node as
DomParentNode).last_element_child) return true;
+ if (element is GElement)
+ if ((element as GNode).get_internal_node ()
+ == ((element.parent_node as
DomParentNode).last_element_child as GNode).get_internal_node ()) return true;
+ }
}
if (s.selector_type == CssSelectorType.CLASS) {
var p = element.get_attribute ("class");
diff --git a/test/CssSelectorTest.vala b/test/CssSelectorTest.vala
index 0ac6159..e06c6ec 100644
--- a/test/CssSelectorTest.vala
+++ b/test/CssSelectorTest.vala
@@ -425,10 +425,10 @@ class CssSelectorTest : GXmlTest {
c4g.set_attribute ("prop", "secondaryvalue");
r2.append_child (c4g);
assert (cp.match (r));
- assert (!cp.match (c1));
- assert (!cp.match (c2));
- assert (!cp.match (c3));
- assert (!cp.match (c4));
+ assert (!cp.match (c1g));
+ assert (!cp.match (c2g));
+ assert (!cp.match (c3g));
+ assert (!cp.match (c4g));
} catch (GLib.Error e){
warning ("ERROR: "+e.message);
}
@@ -519,10 +519,10 @@ class CssSelectorTest : GXmlTest {
c4g.set_attribute ("prop", "secondaryvalue");
r2.append_child (c4g);
assert (cp.match (r));
- assert (!cp.match (c1));
- assert (!cp.match (c2));
- assert (!cp.match (c3));
- assert (!cp.match (c4));
+ assert (!cp.match (c1g));
+ assert (!cp.match (c2g));
+ assert (!cp.match (c3g));
+ assert (!cp.match (c4g));
} catch (GLib.Error e){
warning ("ERROR: "+e.message);
}
@@ -588,10 +588,87 @@ class CssSelectorTest : GXmlTest {
var c6g = d.create_element ("second");
c4g.append_child (c6g);
assert (cp.match (r));
+ assert (!cp.match (c1g));
+ assert (!cp.match (c2g));
+ assert (!cp.match (c3g));
+ assert (!cp.match (c4g));
+ } catch (GLib.Error e){
+ warning ("ERROR: "+e.message);
+ }
+ });
+ Test.add_func ("/gxml/css-selector/pseudo/last-child", () => {
+ try {
+ var cp = new CssSelectorParser ();
+ cp.parse ("second:last-child");
+ foreach (CssSelectorData sel in cp.selectors) {
+ message ("Type: "+sel.selector_type.to_string ()+" : "+sel.data+" :
"+sel.value);
+ }
+ assert (cp.selectors.size == 3);
+ var s = cp.selectors[0];
+ assert (s != null);
+ assert (s.selector_type == CssSelectorType.ELEMENT);
+ var si = cp.selectors[1];
+ assert (si != null);
+ assert (si.selector_type == CssSelectorType.INSIDE);
+ var sa = cp.selectors[2];
+ assert (sa != null);
+ assert (sa.selector_type == CssSelectorType.PSEUDO);
+ var d = new GomDocument ();
+ var r = d.create_element ("toplevel");
+ d.append_child (r);
+ var c1 = d.create_element ("child");
+ r.append_child (c1);
+ var c2 = d.create_element ("child");
+ c2.set_attribute ("prop", "subval");
+ r.append_child (c2);
+ var c3 = d.create_element ("child");
+ c3.set_attribute ("prop", "techval");
+ r.append_child (c3);
+ var c4 = d.create_element ("child");
+ c4.set_attribute ("prop", "secondaryvalue");
+ r.append_child (c4);
+ var c5 = d.create_element ("second");
+ c3.append_child (c5);
+ var c6 = d.create_element ("second");
+ c4.append_child (c6);
+ var c7 = d.create_element ("second");
+ c4.append_child (c7);
+ assert (!cp.match (r));
assert (!cp.match (c1));
assert (!cp.match (c2));
assert (!cp.match (c3));
- assert (!cp.match (c4));
+ assert (cp.match (c4));
+ assert (cp.match (c5));
+ assert (!cp.match (c6));
+ assert (cp.match (c7));
+ var d2 = new GDocument () as DomDocument;
+ var r2 = d2.create_element ("toplevel");
+ d2.append_child (r2);
+ var c1g = d2.create_element ("child");
+ r2.append_child (c1g);
+ var c2g = d2.create_element ("child");
+ c2g.set_attribute ("prop", "subval");
+ r2.append_child (c2g);
+ var c3g = d2.create_element ("child");
+ c3g.set_attribute ("prop", "techval");
+ r2.append_child (c3g);
+ var c4g = d2.create_element ("child");
+ c4g.set_attribute ("prop", "secondaryvalue");
+ r2.append_child (c4g);
+ var c5g = d.create_element ("second");
+ c3g.append_child (c5g);
+ var c6g = d.create_element ("second");
+ c4g.append_child (c6g);
+ var c7g = d.create_element ("second");
+ c4g.append_child (c7g);
+ assert (cp.match (r));
+ assert (!cp.match (c1g));
+ assert (!cp.match (c2g));
+ assert (!cp.match (c3g));
+ assert (cp.match (c4g));
+ assert (cp.match (c5g));
+ assert (!cp.match (c6g));
+ assert (cp.match (c7g));
} catch (GLib.Error e){
warning ("ERROR: "+e.message);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]