The Birdfont Source Code


All Repositories / xmlbird.git / commit – RSS feed

Test XML tree and compile with non null flag

These changes was commited to the Birdfont repository Sun, 03 Jul 2016 19:51:54 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/xmlbird.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 03 Jul 2016 19:51:54 +0000 (21:51 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 03 Jul 2016 19:51:54 +0000 (21:51 +0200)
commit 3f9d94f4f34fd7ea78251ffe8b883cef705e3165
tree f1e9f97d08ef606ed6e6cca7788d424986216216
parent df5cc886f69f8a83661123547167ea55e638625c
Test XML tree and compile with non null flag

libxmlbird/Attributes.vala
libxmlbird/XmlTree.vala
tests/Test.vala
tests/minimal.vala
--- a/libxmlbird/Attributes.vala +++ b/libxmlbird/Attributes.vala @@ -30,21 +30,25 @@ public Iterator iterator () { if (tag != null) { - return new Iterator (tag); + return new Iterator ((!) tag); } - return new Iterator.for_elements (elements); + if (elements != null) { + return new Iterator.for_elements ((!) elements); + } + + return new Iterator.for_elements (new Elements ()); } public class Iterator : GLib.Object { Tag? tag = null; Attribute? next_attribute = null; - Elements elements = null; + Elements? elements = null; int index = 0; internal Iterator (Tag t) { tag = t; - tag.reparse_attributes (); + t.reparse_attributes (); } internal Iterator.for_elements (Elements elements) {
--- a/libxmlbird/XmlTree.vala +++ b/libxmlbird/XmlTree.vala @@ -23,11 +23,13 @@ public class XmlTree : GLib.Object { XmlElement root_element = new XmlElement.empty (); + bool valid = true; public XmlTree (string xml) { XmlParser parser = new XmlParser (xml); if (!parser.validate ()) { + valid = false; XmlParser.warning ("Invalid XML."); return; } @@ -41,8 +43,12 @@ public XmlElement get_root () { return root_element; + } + + public bool validate () { + return valid; } } }
--- a/tests/Test.vala +++ b/tests/Test.vala @@ -14,7 +14,7 @@ namespace B { class Test : GLib.Object { - XmlParser parser; + XmlTree parser; string data; public Test (string xml_data) { @@ -22,7 +22,7 @@ } public bool validate () { - parser = new XmlParser (data); + parser = new XmlTree (data); return parser.validate (); } @@ -49,18 +49,18 @@ } public string get_content () { - Tag root; + XmlElement root; StringBuilder content; - parser = new XmlParser (data); + parser = new XmlTree (data); content = new StringBuilder (); - root = parser.get_root_tag (); + root = parser.get_root (); add_tag (content, root); return content.str.strip (); } - void add_tag (StringBuilder content, Tag tag) { + void add_tag (StringBuilder content, XmlElement tag) { content.append (tag.get_name ()); content.append (" "); @@ -76,13 +76,13 @@ content.append (" "); } - foreach (Tag t in tag) { + foreach (XmlElement t in tag) { add_tag (content, t); } } - bool has_children (Tag tag) { - foreach (Tag t in tag) { + bool has_children (XmlElement tag) { + foreach (XmlElement t in tag) { return true; }
--- a/tests/minimal.vala +++ b/tests/minimal.vala @@ -1,3 +1,4 @@ + public static int main (string[] arg) { B.Test t; @@ -13,9 +14,12 @@ t = new B.Test ("""<root><quote>"<a attr="b" />"</quote></root>"""); t.test ("root quote a attr b"); - t = new B.Test ("""<single />"""); + t = new B.Test ("""<single/>"""); t.test ("single"); - + + t = new B.Test ("""<single_space />"""); + t.test ("single_space"); + return 0; }