From 771c8ecc2f242a7dd8f45ebd91fd253ba37a2a65 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 29 Aug 2010 15:41:16 +0000 Subject: tests: Added more XPath tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@683 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath_parse.cpp | 11 +++++++++++ tests/test_xpath_variables.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index f996b24..aa148be 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -291,4 +291,15 @@ TEST(xpath_parse_out_of_memory_string_to_number) CHECK_XPATH_FAIL(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")); } +TEST(xpath_parse_qname_error) +{ + CHECK_XPATH_FAIL(STR("foo: bar")); + CHECK_XPATH_FAIL(STR("foo :bar")); + CHECK_XPATH_FAIL(STR("foo: *")); + CHECK_XPATH_FAIL(STR("foo :*")); + CHECK_XPATH_FAIL(STR(":*")); + CHECK_XPATH_FAIL(STR(":bar")); + CHECK_XPATH_FAIL(STR(":")); +} + #endif diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index 1ea8b11..f759dc1 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -2,6 +2,8 @@ #include "common.hpp" +#include + TEST(xpath_variables_type_none) { xpath_variable_set set; @@ -323,17 +325,22 @@ TEST(xpath_variables_qname) CHECK_XPATH_BOOLEAN(xml_node(), xpath_query(STR("$foo:bar"), &set), true); } -TEST(xpath_variables_qname_error) +TEST(xpath_variables_name_error) { xpath_variable_set set; set.set(STR("foo:"), true); set.set(STR(":bar"), true); set.set(STR("foo:*"), true); + set.set(STR("foo"), true); + set.set(STR("3"), true); CHECK_XPATH_FAIL_VAR(STR("$foo:"), &set); CHECK_XPATH_FAIL_VAR(STR("$:bar"), &set); CHECK_XPATH_FAIL_VAR(STR("$foo:*"), &set); CHECK_XPATH_FAIL_VAR(STR("$foo:bar:baz"), &set); + CHECK_XPATH_FAIL_VAR(STR("$ foo"), &set); + + CHECK_XPATH_FAIL_VAR(STR("$3"), &set); } TEST(xpath_variables_empty_string) @@ -361,6 +368,27 @@ TEST(xpath_variables_name_case) CHECK_XPATH_NUMBER(xml_node(), xpath_query(STR("$i div $I"), &set), 2.5); } +TEST(xpath_variables_name_unicode) +{ +#ifdef PUGIXML_WCHAR_MODE + #ifdef U_LITERALS + const char_t* name = L"\u0400\u203D"; + #else + const char_t* name = L"\x0400\x203D"; + #endif +#else + const char_t* name = "\xd0\x80\xe2\x80\xbd"; +#endif + + xpath_variable_set set; + set.set(name, STR("value")); + + std::basic_string var = STR("$"); + var += name; + + CHECK_XPATH_STRING(xml_node(), xpath_query(var.c_str(), &set), STR("value")); +} + TEST_XML(xpath_variables_count_sum, "122334") { xpath_variable_set set; -- cgit v1.2.3