diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-06-12 09:04:52 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-06-12 09:04:52 +0000 |
commit | a562014cc24ff060266de8c3cc951263e4efa750 (patch) | |
tree | 3b6f3a0c219e623c983ea77a787cd1a3fc171fa5 /tests | |
parent | 1a007d66e619f0c201efcf7175c2544579c3a8c9 (diff) |
Declaration nodes improvements (they now automatically get name "xml", they can't be inserted as a non-document child, document saving prints declaration only if there is none present in the document)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@517 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_document.cpp | 35 | ||||
-rw-r--r-- | tests/test_dom_modify.cpp | 48 |
2 files changed, 83 insertions, 0 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp index bed9498..11be6da 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -211,6 +211,41 @@ TEST_XML(document_save_declaration, "<node/>") CHECK(writer.as_string() == STR("<?xml version=\"1.0\"?>\n<node />\n"));
}
+TEST_XML(document_save_declaration_present_first, "<node/>")
+{
+ doc.insert_child_before(node_declaration, doc.first_child()).append_attribute(STR("encoding")) = STR("utf8");
+
+ xml_writer_string writer;
+
+ doc.save(writer, STR(""), pugi::format_default, get_native_encoding());
+
+ CHECK(writer.as_string() == STR("<?xml encoding=\"utf8\"?>\n<node />\n"));
+}
+
+TEST_XML(document_save_declaration_present_second, "<node/>")
+{
+ doc.insert_child_before(node_declaration, doc.first_child()).append_attribute(STR("encoding")) = STR("utf8");
+ doc.insert_child_before(node_comment, doc.first_child()).set_value(STR("text"));
+
+ xml_writer_string writer;
+
+ doc.save(writer, STR(""), pugi::format_default, get_native_encoding());
+
+ CHECK(writer.as_string() == STR("<!--text-->\n<?xml encoding=\"utf8\"?>\n<node />\n"));
+}
+
+TEST_XML(document_save_declaration_present_last, "<node/>")
+{
+ doc.append_child(node_declaration).append_attribute(STR("encoding")) = STR("utf8");
+
+ xml_writer_string writer;
+
+ doc.save(writer, STR(""), pugi::format_default, get_native_encoding());
+
+ // node writer only looks for declaration before the first element child
+ CHECK(writer.as_string() == STR("<?xml version=\"1.0\"?>\n<node />\n<?xml encoding=\"utf8\"?>\n"));
+}
+
TEST_XML(document_save_file, "<node/>")
{
#ifdef __unix
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 31647d4..e1e47f7 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -532,3 +532,51 @@ TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />") CHECK(test_node(node, STR("<node attr1=\"3.40282e+038\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw) ||
test_node(node, STR("<node attr1=\"3.40282e+38\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw));
}
+
+TEST(dom_node_declaration_name)
+{
+ xml_document doc;
+ doc.append_child(node_declaration);
+
+ // name 'xml' is auto-assigned
+ CHECK(doc.first_child().type() == node_declaration);
+ CHECK_STRING(doc.first_child().name(), STR("xml"));
+
+ doc.insert_child_after(node_declaration, doc.first_child());
+ doc.insert_child_before(node_declaration, doc.first_child());
+
+ CHECK_NODE(doc, STR("<?xml?><?xml?><?xml?>"));
+}
+
+TEST(dom_node_declaration_top_level)
+{
+ xml_document doc;
+ doc.append_child().set_name(STR("node"));
+
+ xml_node node = doc.first_child();
+ node.append_child(node_pcdata).set_value(STR("text"));
+
+ CHECK(node.insert_child_before(node_declaration, node.first_child()) == xml_node());
+ CHECK(node.insert_child_after(node_declaration, node.first_child()) == xml_node());
+ CHECK(node.append_child(node_declaration) == xml_node());
+
+ CHECK_NODE(doc, STR("<node>text</node>"));
+
+ CHECK(doc.insert_child_before(node_declaration, node));
+ CHECK(doc.insert_child_after(node_declaration, node));
+ CHECK(doc.append_child(node_declaration));
+
+ CHECK_NODE(doc, STR("<?xml?><node>text</node><?xml?><?xml?>"));
+}
+
+TEST(dom_node_declaration_copy)
+{
+ xml_document doc;
+ doc.append_child(node_declaration);
+
+ doc.append_child().set_name(STR("node"));
+
+ doc.last_child().append_copy(doc.first_child());
+
+ CHECK_NODE(doc, STR("<?xml?><node />"));
+}
|