diff --git a/.gitignore b/.gitignore index 74a4312..1b73835 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ /xpath.zip /haxedoc.xml /test.n -/test-java \ No newline at end of file +/test-java +bin/* \ No newline at end of file diff --git a/bin/test.n b/bin/test.n deleted file mode 100644 index 7377bc1..0000000 Binary files a/bin/test.n and /dev/null differ diff --git a/common.hxml b/common.hxml new file mode 100644 index 0000000..b121b40 --- /dev/null +++ b/common.hxml @@ -0,0 +1,3 @@ +-cp src +-cp test +-main xpath.Test \ No newline at end of file diff --git a/src/xpath/expression/PathStep.hx b/src/xpath/expression/PathStep.hx index b72f2f4..a000296 100644 --- a/src/xpath/expression/PathStep.hx +++ b/src/xpath/expression/PathStep.hx @@ -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 = new List().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 = new List().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 diff --git a/src/xpath/xml/XPathHxXml.hx b/src/xpath/xml/XPathHxXml.hx index 7224e34..a635a76 100644 --- a/src/xpath/xml/XPathHxXml.hx +++ b/src/xpath/xml/XPathHxXml.hx @@ -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. */ diff --git a/test/xpath/XPathTest.hx b/test/xpath/XPathTest.hx index 30b7e3a..9f77273 100644 --- a/test/xpath/XPathTest.hx +++ b/test/xpath/XPathTest.hx @@ -1,8 +1,8 @@ /* Haxe XPath by Daniel J. Cassidy * 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 @@ -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()); + } } diff --git a/tests.hxml b/tests.hxml new file mode 100644 index 0000000..aef9ed3 --- /dev/null +++ b/tests.hxml @@ -0,0 +1,4 @@ +common.hxml +-debug +-js bin/test.js +# -cmd neko bin/test.n \ No newline at end of file