diff --git a/test/CharacterDataTest.vala b/test/CharacterDataTest.vala new file mode 100644 index 0000000000000000000000000000000000000000..a242cdf93694d268140a2d63930224a53de335db --- /dev/null +++ b/test/CharacterDataTest.vala @@ -0,0 +1,56 @@ +/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +using GXml.Dom; + +class CharacterDataTest : GXmlTest { + public static void add_tests () { + Test.add_func ("/gxml/characterdata/data", () => { + string str = "It does not do to dwell on dreams and forget to live, remember that."; + Text txt = get_text_new_doc (str); + + assert (txt.data == str); + assert (txt.data == txt.node_value); + }); + Test.add_func ("/gxml/characterdata/length", () => { + string str = "After all, to the well-organized mind, death is but the next great adventure."; + Text txt = get_text_new_doc (str); + + assert (txt.length == str.length); + }); + Test.add_func ("/gxml/characterdata/substring_data", () => { + Text txt = get_text_new_doc ("The trouble is, humans do have a knack of choosing precisely those things that are worst for them."); + string str = txt.substring_data (4, 7); + + assert (str == "trouble"); + + // TODO: test bounds + }); + Test.add_func ("/gxml/characterdata/append_data", () => { + 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."; + Text txt = get_text_new_doc ("Never trust anything that can think for itself"); + + assert (txt.data == str_start); + txt.append_data (" if you can't see where it keeps its brain."); + assert (txt.data == str_whole); + }); + Test.add_func ("/gxml/characterdata/insert_data", () => { + Text txt = get_text_new_doc ("It is our choices that show what we are, far more than our abilities."); + txt.insert_data (35, " truly"); + assert (txt.data == "It is our choices that show what we truly are, far more than our abilities."); + // TODO: test bounds + }); + Test.add_func ("/gxml/characterdata/delete_data", () => { + 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."); + txt.delete_data (14, 65); + assert (txt.data == "Happiness can turn on the light."); + // TODO: test bounds + }); + Test.add_func ("/gxml/characterdata/replace_data", () => { + // TODO: test bounds + + Text txt = get_text_new_doc ("In dreams, we enter a world that's entirely our own."); + 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/GXmlTest.vala b/test/GXmlTest.vala index 8193973adce5640cabd355232a39a67d784cf82b..ffa0b3fa11fadd68e5b9ce3886a2a0bd2c57788d 100644 --- a/test/GXmlTest.vala +++ b/test/GXmlTest.vala @@ -10,6 +10,7 @@ class GXmlTest { AttrTest.add_tests (); NodeListTest.add_tests (); TextTest.add_tests (); + CharacterDataTest.add_tests (); Test.run (); return 1; diff --git a/test/wscript_build b/test/wscript_build index 294023719c59c1b1b080cb70c623fcddcd7996b4..5ea8710a0ad8a9385663788242138d4c97a2ec16 100644 --- a/test/wscript_build +++ b/test/wscript_build @@ -11,7 +11,7 @@ bld.program( target = 'gxml_test', uselib = 'GTK GLIB GEE XML', use = 'gxml', - source = ['AttrTest.vala', 'DocumentTest.vala', 'ElementTest.vala', 'GXmlTest.vala', 'NodeListTest.vala', 'TextTest.vala', 'XNodeTest.vala'], + source = ['AttrTest.vala', 'CharacterDataTest.vala', 'DocumentTest.vala', 'ElementTest.vala', 'GXmlTest.vala', 'NodeListTest.vala', 'TextTest.vala', 'XNodeTest.vala'], vapi_dirs = '../gxml', valaflags = ['-g'] # TODO: how do we communicate this? Argh! )