Test remaining cases of #1938

This commit is contained in:
Clément Fournier
2020-10-26 17:57:42 +01:00
parent 7a8ca28c3f
commit 0a4dd810c9
2 changed files with 20 additions and 0 deletions

View File

@ -95,6 +95,8 @@ public class DocumentNode extends BaseNodeInfo implements DocumentInfo, AstNodeO
return new Navigator.DescendantEnumeration(this, true, true);
case Axis.CHILD:
return SingleNodeIterator.makeIterator(rootNode);
case Axis.SELF:
return SingleNodeIterator.makeIterator(this);
default:
return super.iterateAxis(axisNumber);
}

View File

@ -64,6 +64,24 @@ public class SaxonXPathRuleQueryTest {
Assert.assertEquals(dummy, result.get(0));
}
@Test
public void testRootExpressionIsADocumentNode() {
DummyNode dummy = new DummyNode(); // todo in pmd 7 this should be a RootNode
List<Node> result = assertQuery(1, "(/)[self::document-node()]", dummy);
Assert.assertEquals(dummy, result.get(0));
}
@Test
public void testRootExpressionWithName() {
DummyNode dummy = new DummyNode(0, false, "DummyNodeA"); // todo in pmd 7 this should be a RootNode
List<Node> result = assertQuery(1, "(/)[self::document-node(element(DummyNodeA))]", dummy);
Assert.assertEquals(dummy, result.get(0));
assertQuery(0, "(/)[self::document-node(element(DummyNodeX))]", dummy);
}
@Test
public void ruleChainVisits() {
SaxonXPathRuleQuery query = createQuery("//dummyNode[@Image='baz']/foo | //bar[@Public = 'true'] | //dummyNode[@Public = false()] | //dummyNode");