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).
This commit is contained in:
Arseny Kapoulkine 2020-02-01 07:44:14 -08:00
parent 41b6ff21c4
commit 85a39b955d

View file

@ -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