summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-04 10:40:18 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-03-04 10:44:08 -0800
commit5a848de085e8f2b0458ee7afba5a3d95572f11c2 (patch)
tree1c30c4643d143a01ee1e30c07bcdd2b2d8b65776
parentcb04ab2700611f68f8690e73b21c34024a13acc6 (diff)
tests: Fix XPath string comparison
Also add new tests for translate. These are technically redundant since other tests would catch the bug with the fixed comparison, but more tests is better.
-rw-r--r--tests/test.cpp15
-rw-r--r--tests/test_xpath_functions.cpp8
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/test.cpp b/tests/test.cpp
index eb901db..6347984 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -71,6 +71,15 @@ bool test_double_nan(double value)
}
#ifndef PUGIXML_NO_XPATH
+static size_t strlength(const pugi::char_t* s)
+{
+#ifdef PUGIXML_WCHAR_MODE
+ return wcslen(s);
+#else
+ return strlen(s);
+#endif
+}
+
bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables, const pugi::char_t* expected)
{
pugi::xpath_query q(query, variables);
@@ -81,7 +90,11 @@ bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query,
size_t size = q.evaluate_string(result, capacity, node);
- if (size <= capacity) return test_string_equal(result, expected);
+ if (size != strlength(expected) + 1)
+ return false;
+
+ if (size <= capacity)
+ return test_string_equal(result, expected);
std::basic_string<pugi::char_t> buffer(size, ' ');
diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp
index 678bc2e..eb43bb5 100644
--- a/tests/test_xpath_functions.cpp
+++ b/tests/test_xpath_functions.cpp
@@ -570,6 +570,14 @@ TEST(xpath_string_translate_table)
CHECK_XPATH_STRING(c, STR("translate('abcde', 'abcd', concat('ABC', 'D'))"), STR("ABCDe"));
}
+TEST(xpath_string_translate_remove)
+{
+ xml_node c;
+
+ CHECK_XPATH_STRING(c, STR("translate('000000755', '0', '')"), STR("755"));
+ CHECK_XPATH_STRING(c, STR("translate('000000755', concat('0', ''), '')"), STR("755"));
+}
+
TEST_XML(xpath_nodeset_last, "<node><c1/><c1/><c2/><c3/><c3/><c3/><c3/></node>")
{
xml_node n = doc.child(STR("node"));