mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-27 13:33:17 +08:00
tests: Added more XPath tests based on recommendation errata
git-svn-id: http://pugixml.googlecode.com/svn/trunk@483 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
a2433c90a2
commit
d8b256203c
@ -81,6 +81,14 @@ TEST(xpath_number_floor)
|
||||
|
||||
// floor with 2 arguments
|
||||
CHECK_XPATH_FAIL(STR("floor(1, 2)"));
|
||||
|
||||
// floor with argument 0 should return 0
|
||||
CHECK_XPATH_STRING(c, STR("string(1 div floor(0))"), STR("Infinity"));
|
||||
|
||||
// floor with argument -0 should return -0
|
||||
#if !(defined(__APPLE__) && defined(__MACH__)) // MacOS X gcc 4.0.1 implements floor incorrectly (floor never returns -0)
|
||||
CHECK_XPATH_STRING(c, STR("string(1 div floor(-0))"), STR("-Infinity"));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(xpath_number_ceiling)
|
||||
@ -102,9 +110,10 @@ TEST(xpath_number_ceiling)
|
||||
// ceiling with 2 arguments
|
||||
CHECK_XPATH_FAIL(STR("ceiling(1, 2)"));
|
||||
|
||||
// ceiling with argument in range (-1, -0] should result in minus zero
|
||||
// ceiling with argument 0 should return 0
|
||||
CHECK_XPATH_STRING(c, STR("string(1 div ceiling(0))"), STR("Infinity"));
|
||||
|
||||
// ceiling with argument in range (-1, -0] should result in minus zero
|
||||
#if !(defined(__APPLE__) && defined(__MACH__)) // MacOS X gcc 4.0.1 implements ceil incorrectly (ceil never returns -0)
|
||||
CHECK_XPATH_STRING(c, STR("string(1 div ceiling(-0))"), STR("-Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("string(1 div ceiling(-0.1))"), STR("-Infinity"));
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
TEST_XML(xpath_operators_arithmetic, "<node><foo-bar>10</foo-bar><foo>2</foo><bar>3</bar></node>")
|
||||
TEST(xpath_operators_arithmetic)
|
||||
{
|
||||
xml_node c;
|
||||
xml_node n = doc.child(STR("node"));
|
||||
|
||||
// incorrect unary operator
|
||||
CHECK_XPATH_FAIL(STR("-"));
|
||||
@ -43,6 +42,17 @@ TEST_XML(xpath_operators_arithmetic, "<node><foo-bar>10</foo-bar><foo>2</foo><ba
|
||||
CHECK_XPATH_NUMBER(c, STR("2+-2"), 0);
|
||||
CHECK_XPATH_NUMBER(c, STR("1-2-3"), -4);
|
||||
|
||||
// mod, from W3C standard
|
||||
CHECK_XPATH_NUMBER(c, STR("5 mod 2"), 1);
|
||||
CHECK_XPATH_NUMBER(c, STR("5 mod -2"), 1);
|
||||
CHECK_XPATH_NUMBER(c, STR("-5 mod 2"), -1);
|
||||
CHECK_XPATH_NUMBER(c, STR("-5 mod -2"), -1);
|
||||
}
|
||||
|
||||
TEST(xpath_operators_arithmetic_specials)
|
||||
{
|
||||
xml_node c;
|
||||
|
||||
// infinity/nan
|
||||
CHECK_XPATH_STRING(c, STR("1 div 0"), STR("Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("-1 div 0"), STR("-Infinity"));
|
||||
@ -53,12 +63,19 @@ TEST_XML(xpath_operators_arithmetic, "<node><foo-bar>10</foo-bar><foo>2</foo><ba
|
||||
CHECK_XPATH_STRING(c, STR("1 div 0 + 100"), STR("Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("-1 div 0 + 100"), STR("-Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("0 div 0 + 100"), STR("NaN"));
|
||||
|
||||
// unary - and multiplication clarifications from recommendations errata
|
||||
CHECK_XPATH_STRING(c, STR("1 div -0"), STR("-Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("-1 div -0"), STR("Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("1 div (-0 * 1)"), STR("-Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("-1 div (0 * -1)"), STR("Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("1 div (-0 div 1)"), STR("-Infinity"));
|
||||
CHECK_XPATH_STRING(c, STR("-1 div (0 div -1)"), STR("Infinity"));
|
||||
}
|
||||
|
||||
// mod, from W3C standard
|
||||
CHECK_XPATH_NUMBER(c, STR("5 mod 2"), 1);
|
||||
CHECK_XPATH_NUMBER(c, STR("5 mod -2"), 1);
|
||||
CHECK_XPATH_NUMBER(c, STR("-5 mod 2"), -1);
|
||||
CHECK_XPATH_NUMBER(c, STR("-5 mod -2"), -1);
|
||||
TEST_XML(xpath_operators_arithmetic_subtraction_parse, "<node><foo-bar>10</foo-bar><foo>2</foo><bar>3</bar></node>")
|
||||
{
|
||||
xml_node n = doc.child(STR("node"));
|
||||
|
||||
// correct subtraction parsing, from W3C standard
|
||||
CHECK_XPATH_NUMBER(n, STR("foo-bar"), 10);
|
||||
|
Loading…
x
Reference in New Issue
Block a user