[gxml] Implemented CssSelectorParser E[foo~="bar"] selector
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Implemented CssSelectorParser E[foo~="bar"] selector
- Date: Fri, 8 Sep 2017 17:03:50 +0000 (UTC)
commit b37a40d2b64d3b2f5ba4f15627766bb37a103633
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Sep 8 07:52:25 2017 -0700
Implemented CssSelectorParser E[foo~="bar"] selector
gxml/CssSelectorParser.vala | 6 ++++++
test/CssSelectorTest.vala | 42 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/gxml/CssSelectorParser.vala b/gxml/CssSelectorParser.vala
index d5fb2f8..10805b4 100644
--- a/gxml/CssSelectorParser.vala
+++ b/gxml/CssSelectorParser.vala
@@ -332,6 +332,12 @@ public class GXml.CssSelectorParser : GLib.Object {
if (p == null) return false;
if (p == s.value) return true;
}
+ if (is_element && s.selector_type == CssSelectorType.ATTRIBUTE_CONTAINS) {
+ var p = element.get_attribute (s.data);
+ if (p == null) return false;
+ var tl = new GDomTokenList (element, s.data);
+ if (tl.contains (s.value)) return true;
+ }
if (s.selector_type == CssSelectorType.CLASS) {
var p = element.get_attribute ("class");
if (p == null) return false;
diff --git a/test/CssSelectorTest.vala b/test/CssSelectorTest.vala
index cab9392..3b06a6a 100644
--- a/test/CssSelectorTest.vala
+++ b/test/CssSelectorTest.vala
@@ -62,7 +62,7 @@ class CssSelectorTest : GXmlTest {
warning ("ERROR: "+e.message);
}
});
- Test.add_func ("/gxml/css-selector/element/attribute", () => {
+ Test.add_func ("/gxml/css-selector/element/attribute/value", () => {
try {
var cp = new CssSelectorParser ();
cp.parse ("child[prop]");
@@ -94,6 +94,46 @@ class CssSelectorTest : GXmlTest {
warning ("ERROR: "+e.message);
}
});
+ Test.add_func ("/gxml/css-selector/element/attribute/contains", () => {
+ try {
+ var cp = new CssSelectorParser ();
+ cp.parse ("child[prop~=\"val\"]");
+ 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.ATTRIBUTE_CONTAINS);
+ var d = new GomDocument ();
+ var r = d.create_element ("root");
+ d.append_child (r);
+ var c1 = d.create_element ("child");
+ r.append_child (c1);
+ var c2 = d.create_element ("child");
+ c2.set_attribute ("prop", "val calc soup");
+ r.append_child (c2);
+ var c3 = d.create_element ("child");
+ c3.set_attribute ("prop", "calc val soup");
+ r.append_child (c3);
+ var c4 = d.create_element ("child");
+ c4.set_attribute ("prop", "calc secondary soup");
+ r.append_child (c4);
+ assert (!cp.match (r));
+ assert (!cp.match (c1));
+ assert (cp.match (c2));
+ assert (cp.match (c3));
+ assert (!cp.match (c4));
+ } catch (GLib.Error e){
+ warning ("ERROR: "+e.message);
+ }
+ });
Test.add_func ("/gxml/css-selector/element/attribute-value", () => {
try {
var cp = new CssSelectorParser ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]