diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-10-28 07:40:15 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-10-28 07:40:15 +0000 |
commit | 83183769c1125b3aa489205dd880bf94830831bd (patch) | |
tree | 1fd6fa4666f9796d6be1a5bf382b5777bc2fe39c | |
parent | 3472d0272c8353a7aa6d583651a79dd5db50803f (diff) |
tests: Added function arguments tests, added arithmetic operators tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@181 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r-- | tests/test_xpath_functions.cpp | 32 | ||||
-rw-r--r-- | tests/test_xpath_operators.cpp | 65 |
2 files changed, 93 insertions, 4 deletions
diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index 67aa949..0a2b605 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -116,10 +116,6 @@ TEST(xpath_number_round) // round with 2 arguments
CHECK_XPATH_FAIL("round(1, 2)");
-
- // round with negative zero results
- // $$ CHECK_XPATH_NUMBER(c, "round(-0.3)", -0)
- // $$ CHECK_XPATH_NUMBER(c, "round(-0)", -0)
}
TEST_XML(xpath_boolean_boolean, "<node />")
@@ -498,3 +494,31 @@ TEST(xpath_string_translate) // translate with 4 arguments
CHECK_XPATH_FAIL("translate('a', 'b', 'c', 'd')");
}
+
+TEST(xpath_function_arguments)
+{
+ xml_node c;
+
+ // conversion to string
+ CHECK_XPATH_NUMBER(c, "string-length(12)", 2);
+
+ // conversion to number
+ CHECK_XPATH_NUMBER(c, "round('1.2')", 1);
+ CHECK_XPATH_NUMBER(c, "round('1.7')", 2);
+
+ // conversion to boolean
+ CHECK_XPATH_BOOLEAN(c, "not('1')", false);
+ CHECK_XPATH_BOOLEAN(c, "not('')", true);
+
+ // conversion to node set
+ CHECK_XPATH_FAIL("sum(1)");
+
+ // expression evaluation
+ CHECK_XPATH_NUMBER(c, "round((2 + 2 * 2) div 4)", 2);
+
+ // empty expressions
+ CHECK_XPATH_FAIL("round(,)");
+ CHECK_XPATH_FAIL("substring(,)");
+ CHECK_XPATH_FAIL("substring('a',)");
+ CHECK_XPATH_FAIL("substring(,'a')");
+}
diff --git a/tests/test_xpath_operators.cpp b/tests/test_xpath_operators.cpp new file mode 100644 index 0000000..41005d4 --- /dev/null +++ b/tests/test_xpath_operators.cpp @@ -0,0 +1,65 @@ +#include "common.hpp"
+
+TEST_XML(xpath_operators_arithmetic, "<node><foo-bar>10</foo-bar><foo>2</foo><bar>3</bar></node>")
+{
+ xml_node c;
+ xml_node n = doc.child("node");
+
+ // incorrect unary operator
+ CHECK_XPATH_FAIL("-");
+
+ // correct unary operator
+ CHECK_XPATH_NUMBER(c, "-1", -1);
+ CHECK_XPATH_NUMBER(c, "--1", 1);
+ CHECK_XPATH_NUMBER(c, "---1", -1);
+
+ // incorrect binary operators
+ CHECK_XPATH_FAIL("5+");
+ CHECK_XPATH_FAIL("5-");
+ CHECK_XPATH_FAIL("5*");
+ CHECK_XPATH_FAIL("+5");
+ CHECK_XPATH_FAIL("*5");
+ CHECK_XPATH_FAIL("1div2");
+ CHECK_XPATH_FAIL("1mod");
+ CHECK_XPATH_FAIL("1div");
+
+ // correct trivial binary operators
+ CHECK_XPATH_NUMBER(c, "1 + 2", 3);
+ CHECK_XPATH_NUMBER(c, "1+2", 3);
+ CHECK_XPATH_NUMBER(c, "1 * 2", 2);
+ CHECK_XPATH_NUMBER(c, "1*2", 2);
+ CHECK_XPATH_NUMBER(c, "1 div 2", 0.5);
+
+ // operator precedence
+ CHECK_XPATH_NUMBER(c, "2 + 2 * 2 div 1 mod 3", 3);
+ CHECK_XPATH_NUMBER(c, "2 + 2 * 2 div (1 mod 3)", 6);
+ CHECK_XPATH_NUMBER(c, "(2 + 2) * 2 div (1 mod 3)", 8);
+ CHECK_XPATH_NUMBER(c, "(2 + 2) * (2 div 1) mod 3", 2);
+ CHECK_XPATH_NUMBER(c, "2 - -2", 4);
+ CHECK_XPATH_NUMBER(c, "2--2", 4);
+ CHECK_XPATH_NUMBER(c, "1-2-3", -4);
+
+ // infinity/nan
+ CHECK_XPATH_STRING(c, "1 div 0", "Infinity");
+ CHECK_XPATH_STRING(c, "-1 div 0", "-Infinity");
+ CHECK_XPATH_STRING(c, "-1 div 0 + 1 div 0", "NaN");
+ CHECK_XPATH_STRING(c, "0 div 0", "NaN");
+ CHECK_XPATH_STRING(c, "1 div 0 + 1 div 0", "Infinity");
+ CHECK_XPATH_STRING(c, "-1 div 0 + -1 div 0", "-Infinity");
+ CHECK_XPATH_STRING(c, "1 div 0 + 100", "Infinity");
+ CHECK_XPATH_STRING(c, "-1 div 0 + 100", "-Infinity");
+ CHECK_XPATH_STRING(c, "0 div 0 + 100", "NaN");
+
+ // mod, from W3C standard
+ CHECK_XPATH_NUMBER(c, "5 mod 2", 1);
+ CHECK_XPATH_NUMBER(c, "5 mod -2", 1);
+ CHECK_XPATH_NUMBER(c, "-5 mod 2", -1);
+ CHECK_XPATH_NUMBER(c, "-5 mod -2", -1);
+
+ // correct subtraction parsing, from W3C standard
+ CHECK_XPATH_NUMBER(n, "foo-bar", 10);
+ CHECK_XPATH_NUMBER(n, "foo -bar", -1);
+ CHECK_XPATH_NUMBER(n, "foo - bar", -1);
+ CHECK_XPATH_NUMBER(n, "-foo-bar", -10);
+ CHECK_XPATH_NUMBER(n, "-foo -bar", -5);
+}
|