#ifndef PUGIXML_NO_XPATH
#include "common.hpp"
TEST_XML(xpath_xalan_select_1, "")
{
CHECK_XPATH_STRING(doc, STR("/doc/a/b/@attr"), STR("test"));
}
TEST_XML(xpath_xalan_select_2, "doremifasolatidoG#AAbBbCC#D")
{
xml_node c = doc.child(STR("doc"));
// This should come out fasolatido:
CHECK_XPATH_NODESET(c, STR("fa")) % 12;
// This should come out doremifasolatido:
CHECK_XPATH_NODESET(c, STR("mi | do | fa | re")) % 3 % 6 % 8 % 12;
// This should come out do-do-remi-mi1-mi2fasolatido-fa--so-:
CHECK_XPATH_NODESET(c, STR("mi[@mi2='mi2'] | do | fa/so/@so | fa | mi/@* | re | fa/@fa | do/@do")) % 3 % 4 % 6 % 8 % 9 % 10 % 12 % 13 % 16;
// This should come out solatidoG#:
CHECK_XPATH_NODESET(c, STR(".//*[@so]")) % 15 % 23;
// This should come out relatidoABb:
CHECK_XPATH_NODESET(c, STR("*//la | //Bflat | re")) % 6 % 18 % 28 % 31;
// This should come out domitiACD:
CHECK_XPATH_NODESET(c, STR("fa/../mi | Aflat/natural/la | Csharp//* | /doc/do | *//ti")) % 3 % 8 % 20 % 28 % 34 % 37;
}
TEST_XML(xpath_xalan_select_3, "preceding sibling number 1current nodefollowing sibling number 3cousin 1cousin 2cousin 3")
{
CHECK_XPATH_NODESET(doc.child(STR("doc")).child(STR("sub1")).child(STR("child2")), STR("preceding-sibling::child1|//child3")) % 4 % 8 % 15;
}
TEST_XML(xpath_xalan_select_4, "bad1bad2bad3bad4OKbad5")
{
xml_node c = doc.child(STR("doc"));
CHECK_XPATH_NODESET(c, STR("child::sub")) % 11;
CHECK_XPATH_NODESET(c, STR("child ::sub")) % 11;
CHECK_XPATH_NODESET(c, STR("child:: sub")) % 11;
CHECK_XPATH_NODESET(c, STR("child :: sub")) % 11;
}
TEST_XML_FLAGS(xpath_xalan_select_5, "bad0bad1bad2", parse_default | parse_comments)
{
xml_node c = doc.child(STR("doc"));
CHECK_XPATH_NODESET(c, STR("comment()")) % 4;
CHECK_XPATH_NODESET(c, STR("comment ()")) % 4;
CHECK_XPATH_NODESET(c, STR("comment ( ) ")) % 4;
CHECK_XPATH_NUMBER(c, STR("string-length()"), 12);
CHECK_XPATH_NUMBER(c, STR("string-length ()"), 12);
CHECK_XPATH_NUMBER(c, STR("string-length ( ) "), 12);
}
TEST_XML(xpath_xalan_select_6, "
9
")
{
xml_node c = doc.child(STR("div"));
CHECK_XPATH_NUMBER(doc, STR("div +3"), 12);
CHECK_XPATH_NUMBER(doc, STR("* +3"), 12);
CHECK_XPATH_NUMBER(c, STR("@div - 5"), 15);
CHECK_XPATH_NUMBER(c, STR("@div -5"), 15);
CHECK_XPATH_NUMBER(c, STR("@div-5"), 12);
CHECK_XPATH_NUMBER(c, STR("@*-5"), 15);
CHECK_XPATH_NUMBER(doc, STR("16-div"), 7);
CHECK_XPATH_NUMBER(doc, STR("25-*"), 16);
CHECK_XPATH_NUMBER(doc, STR("54 div*"), 6);
CHECK_XPATH_NUMBER(doc, STR("(* - 4) div 2"), 2.5);
CHECK_XPATH_NUMBER(doc, STR("' 6 ' div 2"), 3);
CHECK_XPATH_NUMBER(doc, STR("' 6 '*div"), 54);
CHECK_XPATH_NUMBER(doc, STR("5.*."), 45);
CHECK_XPATH_NUMBER(doc, STR("5.+."), 14);
}
TEST_XML(xpath_xalan_select_7, "9
8")
{
xml_node c = doc.child(STR("doc"));
CHECK_XPATH_NUMBER(c, STR("attribute :: div"), 20);
CHECK_XPATH_NUMBER(c, STR("attribute :: *"), 20);
CHECK_XPATH_NUMBER(c, STR("attribute*(div - 4)"), 40);
CHECK_XPATH_NUMBER(c, STR("(* - 4)**"), 45);
}
TEST_XML(xpath_xalan_select_8, "x7
y9
z5
")
{
CHECK_XPATH_NODESET(doc, STR("doc/a[div=9]")) % 7;
}
TEST_XML(xpath_xalan_select_9, "7379929920")
{
CHECK_XPATH_NODESET(doc, STR("doc/a[*=9]")) % 9 % 15 % 21;
}
TEST_XML(xpath_xalan_select_10, "child1child2")
{
CHECK_XPATH_NODESET(doc, STR("/doc/sub1/child1|/doc/sub2/child2")) % 4 % 7;
CHECK_XPATH_NODESET(doc.child(STR("doc")), STR("sub1/child1|/doc/sub2/child2")) % 4 % 7;
CHECK_XPATH_NODESET(doc.child(STR("doc")), STR("sub1/child1|sub2/child2")) % 4 % 7;
CHECK_XPATH_NODESET(doc, STR("//self::child1|//self::child2")) % 4 % 7;
CHECK_XPATH_NODESET(doc, STR("//child1|//child2")) % 4 % 7;
CHECK_XPATH_NODESET(doc, STR("//child1|//child2|//child3")) % 4 % 7 % 10;
}
TEST_XML(xpath_xalan_select_11, "descendant number 1descendant number 2")
{
CHECK_XPATH_NODESET(doc, STR("//child1/ancestor::sub1|//child1/ancestor::sub2")) % 3 % 7;
}
TEST_XML(xpath_xalan_select_12, "child number 1grandchild number 1child number 2grandchild number 2child number 3grandchild number 3child number 4grandchild number 4")
{
CHECK_XPATH_NODESET(doc, STR("//child/ancestor-or-self::sub | //child/ancestor-or-self::sub-sub")) % 3 % 7 % 15 % 19 % 31;
}
TEST_XML(xpath_xalan_select_13, "Carmelo MontanezNineDavid MarstonSevenMary BradyTenLynne RosenthalFive")
{
CHECK_XPATH_NODESET(doc, STR("doc/book/author[name/@real='no']|doc/book/author[name/@real='yes']")) % 4 % 20;
CHECK_XPATH_NODESET(doc, STR("doc/book/author[(name/@real='no' and position()=1)]|doc/book/author[(name/@real='yes' and position()=last())]")) % 4 % 20;
CHECK_XPATH_NODESET(doc, STR("doc/book/author[name='Mary Brady']|doc/book/author[name/@real='no']")) % 4 % 20;
CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/bibliography/author/name")) % 5 % 13 % 21 % 28;
CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/bibliography/author/chapters")) % 5 % 13 % 21 % 30;
CHECK_XPATH_NODESET(doc, STR("doc/book/author/name|doc/book/author/noElement")) % 5 % 13 % 21;
CHECK_XPATH_NODESET(doc, STR("//noChild1|//noChild2"));
}
TEST_XML(xpath_xalan_select_14, "child number 1child number 2")
{
xml_node c = doc.child(STR("doc"));
CHECK_XPATH_NODESET(c, STR("child::sub1|child::sub2")) % 3 % 7;
CHECK_XPATH_NODESET(c, STR("descendant::child1|descendant::child2")) % 5 % 9;
CHECK_XPATH_NODESET(c, STR("descendant-or-self::sub1|descendant-or-self::sub2")) % 3 % 7;
CHECK_XPATH_NODESET(c.child(STR("sub2")), STR("preceding-sibling::sub1|following-sibling::sub3")) % 3 % 11;
}
TEST_XML(xpath_xalan_select_15, "Selection of this child is an error.Selection of this child is an error.Selection of this child is an error.Selection of this child is an error.EFGSelection of this child is an error.Selection of this child is an error.JKSelection of this child is an error.Selection of this child is an error.NOP")
{
xml_node c = doc.child(STR("doc"));
CHECK_XPATH_NODESET(c, STR("child[@wide='3']|child[@deep='3']")) % 15 % 18 % 22 % 35 % 39 % 51 % 54 % 58;
CHECK_XPATH_NODESET(c, STR("child[@deep='3']|child[@wide='3']")) % 15 % 18 % 22 % 35 % 39 % 51 % 54 % 58;
}
TEST_XML(xpath_xalan_select_16, "1234")
{
CHECK_XPATH_NUMBER(doc, STR("count(doc/a/attribute::*)"), 9);
CHECK_XPATH_NUMBER(doc, STR("count(//@*)"), 9);
CHECK_XPATH_NUMBER(doc, STR("count(//@squish)"), 3);
}
TEST_XML(xpath_xalan_select_17, "")
{
xml_node c = doc.child(STR("directions"));
CHECK_XPATH_NODESET(c, STR("north/* | north/dup1 | north/dup2")) % 4 % 5 % 6 % 7 % 8;
CHECK_XPATH_NODESET(c, STR("north/dup2 | north/dup1 | north/*")) % 4 % 5 % 6 % 7 % 8;
CHECK_XPATH_NODESET(c, STR("//north/dup2 | south/preceding-sibling::*[4]/* | north/dup1 | north/*")) % 4 % 5 % 6 % 7 % 8;
CHECK_XPATH_NODESET(c, STR("north/dup2 | south/preceding-sibling::*[4]/* | north/*")) % 4 % 5 % 6 % 7 % 8;
}
TEST_XML(xpath_xalan_select_18, "HelloThereWorld")
{
CHECK_XPATH_NODESET(doc, STR("/para/font[@color='green']")) % 6;
CHECK_XPATH_NODESET(doc.child(STR("para")), STR("/para/font[@color='green']")) % 6;
CHECK_XPATH_NODESET(doc.child(STR("para")).last_child(), STR("/para/font[@color='green']")) % 6;
}
TEST_XML_FLAGS(xpath_xalan_select_19, "1in-a2345678in-c9", parse_default | parse_comments | parse_pi)
{
CHECK_XPATH_NODESET(doc, STR("//*")) % 2 % 4 % 8 % 10 % 12 % 18;
CHECK_XPATH_NODESET(doc, STR("//node()")) % 2 % 3 % 4 % 5 % 6 % 7 % 8 % 9 % 10 % 11 % 12 % 13 % 14 % 15 % 16 % 17 % 18 % 19 % 20 % 21;
CHECK_XPATH_NODESET(doc, STR("//text()")) % 3 % 5 % 6 % 9 % 11 % 13 % 14 % 15 % 17 % 19 % 20;
CHECK_XPATH_NODESET(doc, STR("//comment()")) % 7 % 16;
CHECK_XPATH_NODESET(doc, STR("//processing-instruction()")) % 21;
}
TEST_XML(xpath_xalan_bugzilla_1, "15152252")
{
CHECK_XPATH_NODESET(doc, STR("/report/colData[@colId='F' and not(.=preceding::colData)]")) % 3;
}
TEST(xpath_xalan_error_boolean)
{
CHECK_XPATH_FAIL(STR("nt(true())"));
CHECK_XPATH_FAIL(STR("not(troo())"));
CHECK_XPATH_FAIL(STR("troo() and (2 = 2)"));
CHECK_XPATH_FAIL(STR("troo() or (2 = 2)"));
CHECK_XPATH_FAIL(STR("2 = troo()"));
CHECK_XPATH_FAIL(STR("boolean(troo())"));
CHECK_XPATH_FAIL(STR("true(doc)"));
CHECK_XPATH_FAIL(STR("false(doc)"));
CHECK_XPATH_FAIL(STR("not()"));
CHECK_XPATH_FAIL(STR("not(false(), doc)"));
CHECK_XPATH_FAIL(STR("boolean()"));
CHECK_XPATH_FAIL(STR("boolean(false(), doc)"));
CHECK_XPATH_FAIL(STR("lang()"));
CHECK_XPATH_FAIL(STR("lang('en','us')"));
}
TEST(xpath_xalan_error_conditional)
{
CHECK_XPATH_FAIL(STR(""));
CHECK_XPATH_FAIL(STR("@name='John' | @name='Joe'"));
CHECK_XPATH_FAIL(STR("\x95not(name(.)='')"));
}
TEST(xpath_xalan_error_match)
{
CHECK_XPATH_FAIL(STR("//"));
CHECK_XPATH_FAIL(STR("section1|"));
CHECK_XPATH_FAIL(STR("|section1"));
}
TEST(xpath_xalan_error_math)
{
CHECK_XPATH_FAIL(STR("6 quo 4"));
CHECK_XPATH_FAIL(STR("-troo()"));
CHECK_XPATH_FAIL(STR("number(troo())"));
CHECK_XPATH_FAIL(STR("5 * troo()"));
CHECK_XPATH_FAIL(STR("12 div troo()"));
CHECK_XPATH_FAIL(STR("number(8,doc)"));
CHECK_XPATH_FAIL(STR("sum(doc, 8)"));
CHECK_XPATH_FAIL(STR("sum()"));
CHECK_XPATH_FAIL(STR("floor(8,7)"));
CHECK_XPATH_FAIL(STR("floor()"));
CHECK_XPATH_FAIL(STR("ceiling(8,7)"));
CHECK_XPATH_FAIL(STR("ceiling()"));
CHECK_XPATH_FAIL(STR("round(8,7)"));
CHECK_XPATH_FAIL(STR("round()"));
}
TEST(xpath_xalan_error_namespace)
{
CHECK_XPATH_FAIL(STR("local-name(baz2:b,..)"));
CHECK_XPATH_FAIL(STR("namespace-uri(baz2:b,..)"));
CHECK_XPATH_FAIL(STR("name(a,b)"));
CHECK_XPATH_FAIL(STR(":foo"));
CHECK_XPATH_FAIL(STR("*:foo"));
}
TEST(xpath_xalan_error_position)
{
CHECK_XPATH_FAIL(STR("*[last(*,2)]"));
CHECK_XPATH_FAIL(STR("position(b)=1"));
CHECK_XPATH_FAIL(STR("count()"));
CHECK_XPATH_FAIL(STR("count(*,4)"));
CHECK_XPATH_FAIL(STR("position()=last(a)"));
}
TEST(xpath_xalan_error_select)
{
CHECK_XPATH_FAIL(STR(""));
CHECK_XPATH_FAIL(STR("count(troo())"));
CHECK_XPATH_FAIL(STR("c::sub"));
CHECK_XPATH_FAIL(STR("c()"));
CHECK_XPATH_FAIL(STR("(* - 4) foo 2"));
CHECK_XPATH_FAIL(STR("5 . + *"));
CHECK_XPATH_FAIL(STR("4/."));
CHECK_XPATH_FAIL(STR("true()/."));
CHECK_XPATH_FAIL(STR("item//[@type='x']"));
CHECK_XPATH_FAIL(STR("//"));
CHECK_XPATH_FAIL(STR("item//"));
CHECK_XPATH_FAIL(STR("count(//)"));
CHECK_XPATH_FAIL(STR("substring-after(//,'0')"));
CHECK_XPATH_FAIL(STR("//+17"));
CHECK_XPATH_FAIL(STR("//|subitem"));
CHECK_XPATH_FAIL(STR("..[near-north]"));
}
TEST(xpath_xalan_error_string)
{
CHECK_XPATH_FAIL(STR("string(troo())"));
CHECK_XPATH_FAIL(STR("string-length(troo())"));
CHECK_XPATH_FAIL(STR("normalize-space(a,'\t\r\n ab cd ')"));
CHECK_XPATH_FAIL(STR("contains('ENCYCLOPEDIA')"));
CHECK_XPATH_FAIL(STR("contains('ENCYCLOPEDIA','LOPE',doc)"));
CHECK_XPATH_FAIL(STR("starts-with('ENCYCLOPEDIA')"));
CHECK_XPATH_FAIL(STR("starts-with('ENCYCLOPEDIA','LOPE',doc)"));
CHECK_XPATH_FAIL(STR("substring-before('ENCYCLOPEDIA')"));
CHECK_XPATH_FAIL(STR("substring-before('ENCYCLOPEDIA','LOPE',doc)"));
CHECK_XPATH_FAIL(STR("substring-after('ENCYCLOPEDIA')"));
CHECK_XPATH_FAIL(STR("substring-after('ENCYCLOPEDIA','LOPE',doc)"));
CHECK_XPATH_FAIL(STR("substring('ENCYCLOPEDIA')"));
CHECK_XPATH_FAIL(STR("substring('ENCYCLOPEDIA',4,5,2)"));
CHECK_XPATH_FAIL(STR("concat('x')"));
CHECK_XPATH_FAIL(STR("string-length('ENCYCLOPEDIA','PEDI')"));
CHECK_XPATH_FAIL(STR("translate('bar','abc')"));
CHECK_XPATH_FAIL(STR("translate('bar','abc','ABC','output')"));
CHECK_XPATH_FAIL(STR("string(22,44)"));
CHECK_XPATH_FAIL(STR("concat(/*)"));
}
#endif