Skip to content
This repository was archived by the owner on Dec 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/xpath.zip
/haxedoc.xml
/test.n
/test-java
/test-java
bin/*
Binary file removed bin/test.n
Binary file not shown.
3 changes: 3 additions & 0 deletions common.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-cp src
-cp test
-main xpath.Test
50 changes: 25 additions & 25 deletions src/xpath/expression/PathStep.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ class PathStep implements Expression {
if (nextStep == null) {
return new XPathNodeSet(step(context));
} else {
var me = this;
var index = 0;
var selected = Lambda.array(step(context));
var nextNode = null;
var nextStepNodes:Iterator<XPathXml> = new List<XPathXml>().iterator();
var hasNext = function() {
return nextNode != null;
};
var next = function() {
var node = nextNode;
while (!nextStepNodes.hasNext() && index < selected.length) {
var nextStepContext = new Context(selected[index], index + 1, selected.length, context.environment);
var nextStepResult = me.nextStep.evaluate(nextStepContext);
nextStepNodes = nextStepResult.getNodes().iterator();
++index;
}
if (nextStepNodes.hasNext()) {
nextNode = nextStepNodes.next();
} else {
nextNode = null;
}
return node;
};
next();
var iterator = function() {
function iterator() {
var me = this;
var index = 0;
var selected = Lambda.array(step(context));
var nextNode = null;
var nextStepNodes:Iterator<XPathXml> = new List<XPathXml>().iterator();
var hasNext = function() {
return nextNode != null;
};
var next = function() {
var node = nextNode;
while (!nextStepNodes.hasNext() && index < selected.length) {
var nextStepContext = new Context(selected[index], index + 1, selected.length, context.environment);
var nextStepResult = me.nextStep.evaluate(nextStepContext);
nextStepNodes = nextStepResult.getNodes().iterator();
++index;
}
if (nextStepNodes.hasNext()) {
nextNode = nextStepNodes.next();
} else {
nextNode = null;
}
return node;
};
next();
return {
hasNext: hasNext,
next: next
Expand Down
10 changes: 7 additions & 3 deletions src/xpath/xml/XPathHxXml.hx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ class XPathHxXml extends XPathXml {
/** Tests if this [XPathXml] represents the same node as the
* [operand]. */
override public function is(operand:XPathXml):Bool {
return Std.is(operand, XPathHxXml) &&
hxXml == cast(operand, XPathHxXml).hxXml &&
attributeName == cast(operand, XPathHxXml).attributeName;
if (!Std.is(operand, XPathHxXml)) {
return false;
}
var typedOperand:XPathHxXml = cast operand;
return hxXml == typedOperand.hxXml &&
attributeName == typedOperand.attributeName &&
attributeParent == typedOperand.attributeParent;
}

/** Gets an iterator over this node's attributes. */
Expand Down
12 changes: 10 additions & 2 deletions test/xpath/XPathTest.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Haxe XPath by Daniel J. Cassidy <mail@danielcassidy.me.uk>
* Dedicated to the Public Domain
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Expand Down Expand Up @@ -268,4 +268,12 @@ class XPathTest extends TestCase {
}
assertTrue(caught);
}

function testComplexContains() {
var xpathXml = XPathHxXml.wrapNode(xml);
var xpathQry = new XPath("//*[contains(@name, 'bar')]");
var nodes = Lambda.array(xpathQry.selectNodes(xpathXml));
assertEquals(1, nodes.length);
assertEquals(e, cast(nodes[0], XPathHxXml).getWrappedXml());
}
}
4 changes: 4 additions & 0 deletions tests.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
common.hxml
-debug
-js bin/test.js
# -cmd neko bin/test.n