summaryrefslogtreecommitdiff
path: root/tests/test_parse.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-02-25 03:41:57 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-02-25 03:41:57 +0000
commit5a4cedbe912e1dd9fac1e4b5f0a5b33b0b1900f8 (patch)
treee9f2972031da7033010e4f4af4f29d32cbf27c2c /tests/test_parse.cpp
parent0a747e6c1aba8218bda284477701044328fc50bb (diff)
tests: Add tests for parse_trim_pcdata.
git-svn-id: https://pugixml.googlecode.com/svn/trunk@988 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_parse.cpp')
-rw-r--r--tests/test_parse.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index c9eeb82..38b09f5 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -425,6 +425,62 @@ TEST(parse_pcdata_error)
CHECK(doc.load(STR("<root>pcdata"), parse_minimal).status == status_end_element_mismatch);
}
+TEST(parse_pcdata_trim)
+{
+ struct test_data_t
+ {
+ const pugi::char_t* source;
+ const pugi::char_t* result;
+ unsigned int flags;
+ };
+
+ test_data_t test_data[] =
+ {
+ { STR("<node> text</node>"), STR("text"), 0 },
+ { STR("<node>\t\n text</node>"), STR("text"), 0 },
+ { STR("<node>text </node>"), STR("text"), 0 },
+ { STR("<node>text \t\n</node>"), STR("text"), 0 },
+ { STR("<node>\r\n\t text \t\n\r</node>"), STR("text"), 0 },
+ { STR(" text"), STR("text"), parse_fragment },
+ { STR("\t\n text"), STR("text"), parse_fragment },
+ { STR("text "), STR("text"), parse_fragment },
+ { STR("text \t\n"), STR("text"), parse_fragment },
+ { STR("\r\n\t text \t\n\r"), STR("text"), parse_fragment },
+ { STR("<node>\r\n\t text \t\n\r more \r\n\t</node>"), STR("text \t\n\r more"), 0 },
+ { STR("<node>\r\n\t text \t\n\r more \r\n\t</node>"), STR("text \t\n\n more"), parse_eol },
+ { STR("<node>\r\n\t text \r\n\r\n\r\n\r\n\r\n\r\n\r\n more \r\n\t</node>"), STR("text \n\n\n\n\n\n\n more"), parse_eol },
+ { STR("<node> test&amp;&amp;&amp;&amp;&amp;&amp;&amp; </node>"), STR("test&amp;&amp;&amp;&amp;&amp;&amp;&amp;"), 0 },
+ { STR("<node> test&amp;&amp;&amp;&amp;&amp;&amp;&amp; </node>"), STR("test&&&&&&&"), parse_escapes },
+ { STR(" test&amp;&amp;&amp;&amp;&amp;&amp;&amp; "), STR("test&&&&&&&"), parse_fragment | parse_escapes }
+ };
+
+ for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i)
+ {
+ const test_data_t& td = test_data[i];
+
+ xml_document doc;
+ CHECK(doc.load(td.source, td.flags | parse_trim_pcdata));
+
+ const pugi::char_t* value = doc.child(STR("node")) ? doc.child_value(STR("node")) : doc.text().get();
+ CHECK_STRING(value, td.result);
+ }
+}
+
+TEST(parse_pcdata_trim_empty)
+{
+ unsigned int flags[] = { 0, parse_ws_pcdata, parse_ws_pcdata_single, parse_ws_pcdata | parse_ws_pcdata_single };
+
+ for (size_t i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i)
+ {
+ xml_document doc;
+ CHECK(doc.load(STR("<node> </node>"), flags[i] | parse_trim_pcdata));
+
+ xml_node node = doc.child(STR("node"));
+ CHECK(node);
+ CHECK(!node.first_child());
+ }
+}
+
TEST(parse_escapes_skip)
{
xml_document doc;