[gxml] Fixed most Unit Tests for CssSelectorParser



commit 2945a4bddb5cf721e4cbeb39304bf1f640114788
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Sep 10 17:46:16 2017 -0700

    Fixed most Unit Tests for CssSelectorParser

 gxml/CssSelectorParser.vala |   11 +-----
 gxml/GHtml.vala             |    2 +-
 test/CssSelectorTest.vala   |   87 ++++++++++++++++---------------------------
 3 files changed, 34 insertions(+), 66 deletions(-)
---
diff --git a/gxml/CssSelectorParser.vala b/gxml/CssSelectorParser.vala
index 48f66f9..b8a3e1a 100644
--- a/gxml/CssSelectorParser.vala
+++ b/gxml/CssSelectorParser.vala
@@ -304,16 +304,7 @@ public class GXml.CssSelectorParser : GLib.Object {
                                CssSelectorData data = new CssSelectorData.with_values 
(CssSelectorType.PARENT, ">", "");
                                list.add (data);
                        }
-//                     if (list.size > 0 && list[list.size - 1].selector_type != CssSelectorType.AND && 
list[list.size - 1].selector_type != CssSelectorType.PARENT
-//                             && list[list.size - 1].selector_type != CssSelectorType.BEFORE && 
list[list.size - 1].selector_type != CssSelectorType.AFTER
-//                             && list[list.size - 1].selector_type == CssSelectorType.ELEMENT && position < 
css.length)
-//                     {
-//                             
-//                     }
                }
-               
-               foreach (var data in list)
-                       message ("%s\n", data.selector_type.to_string());
        }
        public bool match (DomElement element) throws GLib.Error {
                bool is_element = false;
@@ -381,7 +372,7 @@ public class GXml.CssSelectorParser : GLib.Object {
                                if (s.data.down () == "empty") {
                                        if (!element.has_child_nodes ()) return true;
                                }
-                               if (s.data.down () == "fist-child") {
+                               if (s.data.down () == "first-child") {
                                        if (element.parent_node == null) return false;
                                        if (!(element.parent_node is DomElement)) return false;
                                        if (element is GomElement)
diff --git a/gxml/GHtml.vala b/gxml/GHtml.vala
index 67178ed..a260ff5 100644
--- a/gxml/GHtml.vala
+++ b/gxml/GHtml.vala
@@ -29,7 +29,7 @@ namespace GXml {
        /**
    * HML parsing suport. Document handling
    */
-       public class GHtmlDocument : GXml.GDocument, GXml.DomHtmlDocument {
+       public class GHtmlDocument : GDocument, DomHtmlDocument {
                public static int default_options {
                        get {
                                return Html.ParserOption.NONET | Html.ParserOption.NOWARNING | 
Html.ParserOption.NOERROR | Html.ParserOption.NOBLANKS;
diff --git a/test/CssSelectorTest.vala b/test/CssSelectorTest.vala
index e06c6ec..bc49c1e 100644
--- a/test/CssSelectorTest.vala
+++ b/test/CssSelectorTest.vala
@@ -66,9 +66,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse ("child[prop]");
-                               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);
@@ -98,9 +95,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -138,9 +132,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -178,9 +169,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -218,9 +206,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -258,9 +243,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -293,9 +275,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse (".warning");
-                               foreach (CssSelectorData sel in cp.selectors) {
-                                       message ("Type: "+sel.selector_type.to_string ()+" : "+sel.data+" : 
"+sel.value);
-                               }
                                assert (cp.selectors.size == 2);
                                var s = cp.selectors[0];
                                assert (s != null);
@@ -334,9 +313,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse ("child.warning");
-                               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);
@@ -378,9 +354,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse ("toplevel:root");
-                               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);
@@ -437,9 +410,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse ("radio[enable=\"true\"]");
-                               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);
@@ -460,7 +430,7 @@ class CssSelectorTest : GXmlTest {
                                r.append_child (c2);
                                assert (!cp.match (r));
                                assert (!cp.match (c1));
-                               assert (!cp.match (c2));
+                               assert (cp.match (c2));
                        } catch (GLib.Error e){
                                warning ("ERROR: "+e.message);
                        }
@@ -468,10 +438,7 @@ class CssSelectorTest : GXmlTest {
                Test.add_func ("/gxml/css-selector/pseudo/empty", () => {
                        try {
                                var cp = new CssSelectorParser ();
-                               cp.parse ("toplevel:root");
-                               foreach (CssSelectorData sel in cp.selectors) {
-                                       message ("Type: "+sel.selector_type.to_string ()+" : "+sel.data+" : 
"+sel.value);
-                               }
+                               cp.parse ("child:empty");
                                assert (cp.selectors.size == 3);
                                var s = cp.selectors[0];
                                assert (s != null);
@@ -498,12 +465,17 @@ class CssSelectorTest : GXmlTest {
                                r.append_child (c4);
                                var c5 = d.create_element ("common");
                                c4.append_child (c5);
+                               assert (!c1.has_child_nodes ());
+                               assert (!c2.has_child_nodes ());
+                               assert (!c3.has_child_nodes ());
+                               assert (c4.has_child_nodes ());
+                               assert (!c5.has_child_nodes ());
                                assert (!cp.match (r));
                                assert (cp.match (c1));
                                assert (cp.match (c2));
                                assert (cp.match (c3));
                                assert (!cp.match (c4));
-                               assert (cp.match (c5));
+                               assert (!cp.match (c5));
                                var d2 = new GDocument () as DomDocument;
                                var r2 = d2.create_element ("toplevel");
                                d2.append_child (r2);
@@ -518,11 +490,14 @@ class CssSelectorTest : GXmlTest {
                                var c4g = d2.create_element ("child");
                                c4g.set_attribute ("prop", "secondaryvalue");
                                r2.append_child (c4g);
-                               assert (cp.match (r));
-                               assert (!cp.match (c1g));
-                               assert (!cp.match (c2g));
-                               assert (!cp.match (c3g));
+                               var c5g = d2.create_element ("common");
+                               c4g.append_child (c5g);
+                               assert (!cp.match (r));
+                               assert (cp.match (c1g));
+                               assert (cp.match (c2g));
+                               assert (cp.match (c3g));
                                assert (!cp.match (c4g));
+                               assert (!cp.match (c5g));
                        } catch (GLib.Error e){
                                warning ("ERROR: "+e.message);
                        }
@@ -531,9 +506,6 @@ class CssSelectorTest : GXmlTest {
                        try {
                                var cp = new CssSelectorParser ();
                                cp.parse ("second:first-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);
@@ -562,6 +534,12 @@ class CssSelectorTest : GXmlTest {
                                c3.append_child (c5);
                                var c6 = d.create_element ("second");
                                c4.append_child (c6);
+                               assert (c1 == (c1.parent_node as DomParentNode).first_element_child);
+                               assert (c2 != (c2.parent_node as DomParentNode).first_element_child);
+                               assert (c3 != (c3.parent_node as DomParentNode).first_element_child);
+                               assert (c4 != (c4.parent_node as DomParentNode).first_element_child);
+                               assert (c5 == (c5.parent_node as DomParentNode).first_element_child);
+                               assert (c6 == (c6.parent_node as DomParentNode).first_element_child);
                                assert (!cp.match (r));
                                assert (!cp.match (c1));
                                assert (!cp.match (c2));
@@ -583,15 +561,17 @@ class CssSelectorTest : GXmlTest {
                                var c4g = d2.create_element ("child");
                                c4g.set_attribute ("prop", "secondaryvalue");
                                r2.append_child (c4g);
-                               var c5g = d.create_element ("second");
+                               var c5g = d2.create_element ("second");
                                c3g.append_child (c5g);
-                               var c6g = d.create_element ("second");
+                               var c6g = d2.create_element ("second");
                                c4g.append_child (c6g);
-                               assert (cp.match (r));
+                               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));
                        } catch (GLib.Error e){
                                warning ("ERROR: "+e.message);
                        }
@@ -600,9 +580,6 @@ class CssSelectorTest : GXmlTest {
                        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);
@@ -637,7 +614,7 @@ class CssSelectorTest : GXmlTest {
                                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));
@@ -655,17 +632,17 @@ class CssSelectorTest : GXmlTest {
                                var c4g = d2.create_element ("child");
                                c4g.set_attribute ("prop", "secondaryvalue");
                                r2.append_child (c4g);
-                               var c5g = d.create_element ("second");
+                               var c5g = d2.create_element ("second");
                                c3g.append_child (c5g);
-                               var c6g = d.create_element ("second");
+                               var c6g = d2.create_element ("second");
                                c4g.append_child (c6g);
-                               var c7g = d.create_element ("second");
+                               var c7g = d2.create_element ("second");
                                c4g.append_child (c7g);
-                               assert (cp.match (r));
+                               assert (!cp.match (r));
                                assert (!cp.match (c1g));
                                assert (!cp.match (c2g));
                                assert (!cp.match (c3g));
-                               assert (cp.match (c4g));
+                               assert (!cp.match (c4g));
                                assert (cp.match (c5g));
                                assert (!cp.match (c6g));
                                assert (cp.match (c7g));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]