aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2020-02-01 07:44:14 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2020-02-01 07:44:14 -0800
commit85a39b955d353b4db3bafc044b01fbdac43e5183 (patch)
tree68a3918e420f5716ae73b4e47130d13a19869360
parent41b6ff21c455865bb8ef67c5952b7f895b62bacc (diff)
downloadpugixml-85a39b955d353b4db3bafc044b01fbdac43e5183.zip
pugixml-85a39b955d353b4db3bafc044b01fbdac43e5183.tar.gz
pugixml-85a39b955d353b4db3bafc044b01fbdac43e5183.tar.bz2
tests: Add a dedicated test for XPath variable conversion
This makes sure all conversions work as expected (note that no type can be converted to node set so we don't check that).
-rw-r--r--tests/test_xpath_variables.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp
index 3d2147c..adc4464 100644
--- a/tests/test_xpath_variables.cpp
+++ b/tests/test_xpath_variables.cpp
@@ -642,4 +642,30 @@ TEST_XML(xpath_variables_evaluate_node_set_out_of_memory, "<node />")
CHECK_ALLOC_FAIL(q.evaluate_node_set(xml_node()).empty());
}
+
+TEST_XML(xpath_variables_type_conversion, "<node>15</node>")
+{
+ xpath_variable_set set;
+
+ set.set(STR("a"), true);
+ set.set(STR("b"), 42.0);
+ set.set(STR("c"), STR("test"));
+ set.set(STR("d"), doc.select_nodes(STR("node")));
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("boolean($a) = true()"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("number($a) = 1"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("string($a) = 'true'"), &set, true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("boolean($b) = true()"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("number($b) = 42"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("string($b) = '42'"), &set, true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("boolean($c) = true()"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("number($c) = 0"), &set, false);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("string($c) = 'test'"), &set, true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("boolean($d) = true()"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("number($d) = 15"), &set, true);
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("string($d) = '15'"), &set, true);
+}
#endif