From 6938851e9c633c4d20f98133ece19d0692b85ffb Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Sat, 2 May 2015 09:54:49 -0500 Subject: [PATCH] Ported libxml-Text to GXml.Text * Ported all internals and unit tests to xText * Still Unit Test for GXml.Test interface missing --- gxml/Makefile.am | 1 + gxml/libxml-CDATASection.vala | 2 +- gxml/libxml-Document.vala | 8 ++++---- gxml/libxml-Text.vala | 8 ++++---- test/AttrTest.vala | 4 ++-- test/CharacterDataTest.vala | 16 ++++++++-------- test/DocumentTest.vala | 2 +- test/ElementTest.vala | 6 +++--- test/GXmlTest.vala | 6 +++--- test/TextTest.vala | 4 ++-- 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/gxml/Makefile.am b/gxml/Makefile.am index 2c28bc02..a5436512 100644 --- a/gxml/Makefile.am +++ b/gxml/Makefile.am @@ -18,6 +18,7 @@ sources = \ Document.vala \ Namespace.vala \ Node.vala \ + Text.vala \ libxml-Attr.vala \ libxml-AttrChildNodeList.vala \ libxml-BackedNode.vala \ diff --git a/gxml/libxml-CDATASection.vala b/gxml/libxml-CDATASection.vala index fc712a0e..ad625b98 100644 --- a/gxml/libxml-CDATASection.vala +++ b/gxml/libxml-CDATASection.vala @@ -36,7 +36,7 @@ namespace GXml { * {{{ .}}} * It is a type of Text node. For more, see: [[http://www.w3.org/TR/DOM-Level-1/level-one-core.html#ID-667469212]] */ - public class CDATASection : Text { + public class CDATASection : xText { internal CDATASection (Xml.Node *cdata_node, xDocument doc) { base (cdata_node, doc); } diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala index 943fe502..77f171ed 100644 --- a/gxml/libxml-Document.vala +++ b/gxml/libxml-Document.vala @@ -113,7 +113,7 @@ namespace GXml { new xElement (xmlnode, this); break; case NodeType.TEXT: - new Text (xmlnode, this); + new xText (xmlnode, this); break; case NodeType.CDATA_SECTION: new CDATASection (xmlnode, this); @@ -655,9 +655,9 @@ namespace GXml { * @return A new {@link GXml.Text} node containing * the supplied data; this should not be freed */ - public unowned Text create_text_node (string text_data) { - Text text = new Text (this.xmldoc->new_text (text_data), this); - unowned Text ret = text; + public unowned xText create_text_node (string text_data) { + xText text = new xText (this.xmldoc->new_text (text_data), this); + unowned xText ret = text; this.nodes_to_free.append (text); return ret; } diff --git a/gxml/libxml-Text.vala b/gxml/libxml-Text.vala index 3fc112aa..408a8226 100644 --- a/gxml/libxml-Text.vala +++ b/gxml/libxml-Text.vala @@ -41,8 +41,8 @@ namespace GXml { * Version: DOM Level 1 Core<
> * URL: [[http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1312295772]] */ - public class Text : CharacterData { - internal Text (Xml.Node *text_node, xDocument doc) { + public class xText : CharacterData, GXml.Text { + internal xText (Xml.Node *text_node, xDocument doc) { base (text_node, doc); } /** @@ -78,8 +78,8 @@ namespace GXml { * now, it is not attached to the tree as a sibling to * the first part, as the spec wants. */ - public Text split_text (ulong offset) { - Text other; + public xText split_text (ulong offset) { + xText other; this.check_read_only (); diff --git a/test/AttrTest.vala b/test/AttrTest.vala index 3463da82..c8cdd6d6 100644 --- a/test/AttrTest.vala +++ b/test/AttrTest.vala @@ -144,7 +144,7 @@ class AttrTest : GXmlTest { Test.add_func ("/gxml/attribute/insert_before", () => { xDocument doc = get_doc (); Attr attr = get_attr ("pie", "Dumbleberry", doc); - Text txt = doc.create_text_node ("Whipped "); + xText txt = doc.create_text_node ("Whipped "); assert (attr.value == "Dumbleberry"); attr.insert_before (txt, attr.child_nodes.first ()); @@ -155,7 +155,7 @@ class AttrTest : GXmlTest { Test.add_func ("/gxml/attribute/replace_child", () => { xDocument doc = get_doc (); Attr attr = get_attr ("WinningHouse", "Slytherin", doc); - Text txt = doc.create_text_node ("Gryffindor"); + xText txt = doc.create_text_node ("Gryffindor"); assert (attr.value == "Slytherin"); attr.replace_child (txt, attr.child_nodes.item (0)); diff --git a/test/CharacterDataTest.vala b/test/CharacterDataTest.vala index 2b078216..c6df4125 100644 --- a/test/CharacterDataTest.vala +++ b/test/CharacterDataTest.vala @@ -1,4 +1,4 @@ -/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */ /* CharacterDataTest.vala * * Copyright (C) 2011-2013 Richard Schwarting @@ -29,7 +29,7 @@ class CharacterDataTest : GXmlTest { Test.add_func ("/gxml/characterdata/data", () => { string str = "It does not do to dwell on dreams and forget to live, remember that."; xDocument doc; - Text txt = get_text_new_doc (str, out doc); + xText txt = get_text_new_doc (str, out doc); assert (txt.data == str); assert (txt.data == txt.node_value); @@ -37,13 +37,13 @@ class CharacterDataTest : GXmlTest { Test.add_func ("/gxml/characterdata/length", () => { string str = "After all, to the well-organized mind, death is but the next great adventure."; xDocument doc; - Text txt = get_text_new_doc (str, out doc); + xText txt = get_text_new_doc (str, out doc); assert (txt.length == str.length); }); Test.add_func ("/gxml/characterdata/substring_data", () => { xDocument doc; - Text txt = get_text_new_doc ("The trouble is, humans do have a knack of choosing precisely those things that are worst for them.", out doc); + xText txt = get_text_new_doc ("The trouble is, humans do have a knack of choosing precisely those things that are worst for them.", out doc); string str = txt.substring_data (4, 7); assert (str == "trouble"); @@ -54,7 +54,7 @@ class CharacterDataTest : GXmlTest { string str_start = "Never trust anything that can think for itself"; string str_whole = "Never trust anything that can think for itself if you can't see where it keeps its brain."; xDocument doc; - Text txt = get_text_new_doc ("Never trust anything that can think for itself", out doc); + xText txt = get_text_new_doc ("Never trust anything that can think for itself", out doc); assert (txt.data == str_start); txt.append_data (" if you can't see where it keeps its brain."); @@ -62,7 +62,7 @@ class CharacterDataTest : GXmlTest { }); Test.add_func ("/gxml/characterdata/insert_data", () => { xDocument doc; - Text txt = get_text_new_doc ("It is our choices that show what we are, far more than our abilities.", out doc); + xText txt = get_text_new_doc ("It is our choices that show what we are, far more than our abilities.", out doc); txt.insert_data (35, " truly"); assert (txt.data == "It is our choices that show what we truly are, far more than our abilities."); @@ -82,7 +82,7 @@ class CharacterDataTest : GXmlTest { }); Test.add_func ("/gxml/characterdata/delete_data", () => { xDocument doc; - Text txt = get_text_new_doc ("Happiness can be found, even in the darkest of times, if one only remembers to turn on the light.", out doc); + xText txt = get_text_new_doc ("Happiness can be found, even in the darkest of times, if one only remembers to turn on the light.", out doc); txt.delete_data (14, 65); assert (txt.data == "Happiness can turn on the light."); // TODO: test bounds @@ -91,7 +91,7 @@ class CharacterDataTest : GXmlTest { // TODO: test bounds xDocument doc; - Text txt = get_text_new_doc ("In dreams, we enter a world that's entirely our own.", out doc); + xText txt = get_text_new_doc ("In dreams, we enter a world that's entirely our own.", out doc); txt.replace_data (3, 6, "the refrigerator"); assert (txt.data == "In the refrigerator, we enter a world that's entirely our own."); }); diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala index 402e0d3f..e2bd0f7d 100644 --- a/test/DocumentTest.vala +++ b/test/DocumentTest.vala @@ -316,7 +316,7 @@ class DocumentTest : GXmlTest { }); Test.add_func ("/gxml/document/create_text_node", () => { xDocument doc = get_doc (); - Text text = doc.create_text_node ("Star of my dreams"); + xText text = doc.create_text_node ("Star of my dreams"); assert (text.node_name == "#text"); assert (text.node_value == "Star of my dreams"); diff --git a/test/ElementTest.vala b/test/ElementTest.vala index 0c7e5821..f1313058 100644 --- a/test/ElementTest.vala +++ b/test/ElementTest.vala @@ -249,7 +249,7 @@ class ElementTest : GXmlTest { xElement elem; NodeList emails; xElement email; - Text text; + xText text; doc = get_doc (); @@ -264,7 +264,7 @@ class ElementTest : GXmlTest { assert (email.tag_name == "Email"); assert (email.child_nodes.length == 1); - text = (Text)email.child_nodes.@get (0); + text = (xText)email.child_nodes.@get (0); assert (text.node_name == "#text"); assert (text.node_value == "fweasley@hogwarts.co.uk"); @@ -272,7 +272,7 @@ class ElementTest : GXmlTest { assert (email.tag_name == "Email"); assert (email.child_nodes.length == 1); - text = (Text)email.child_nodes.@get (0); + text = (xText)email.child_nodes.@get (0); assert (text.node_name == "#text"); assert (text.node_value == "gweasley@hogwarts.co.uk"); diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala index aada789f..197bb6da 100644 --- a/test/GXmlTest.vala +++ b/test/GXmlTest.vala @@ -118,12 +118,12 @@ class GXmlTest { return elem; } - internal static Text get_text_new_doc (string data, out xDocument doc) { + internal static xText get_text_new_doc (string data, out xDocument doc) { return get_text (data, doc = get_doc ()); } - internal static Text get_text (string data, xDocument doc) { - Text txt = doc.create_text_node (data); + internal static xText get_text (string data, xDocument doc) { + xText txt = doc.create_text_node (data); return txt; } } diff --git a/test/TextTest.vala b/test/TextTest.vala index 89e0af38..f74417f8 100644 --- a/test/TextTest.vala +++ b/test/TextTest.vala @@ -29,8 +29,8 @@ class TextTest : GXmlTest { Test.add_func ("/gxml/text/split_text", () => { xDocument doc; - Text txt1 = get_text_new_doc ("Constant vigilance!", out doc); - Text txt2 = txt1.split_text (5); + xText txt1 = get_text_new_doc ("Constant vigilance!", out doc); + xText txt2 = txt1.split_text (5); assert (txt1.node_value == "Const"); assert (txt2.node_value == "ant vigilance!"); -- GitLab