Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #149 from SYSTRAN/get_child_fix

fix child method: off-by-one error: child(0) == child(1)
  • Loading branch information...
commit 76696fa53dfbe210827af5599c66eeeb603c5377 2 parents a802562 + d2f398f
Roman Shtylman defunctzombie authored
Showing with 13 additions and 13 deletions.
  1. +1 −1  src/xml_element.cc
  2. +2 −2 test/document.js
  3. +10 −10 test/traversal.js
2  src/xml_element.cc
View
@@ -340,7 +340,7 @@ XmlElement::get_child(int32_t idx) {
v8::HandleScope scope;
xmlNode* child = xml_obj->children;
- int32_t i = 1;
+ int32_t i = 0;
while (child && i < idx) {
child = child->next;
++i;
4 test/document.js
View
@@ -44,8 +44,8 @@ module.exports.new_root = function(assert) {
module.exports.one_child = function(assert) {
var doc = libxml.Document();
var root = doc.node('root').node('child-one').parent().node('child-two');
- assert.equal('child-one', doc.child(1).name());
- assert.equal('child-two', doc.child(2).name());
+ assert.equal('child-one', doc.child(0).name());
+ assert.equal('child-two', doc.child(1).name());
assert.done();
};
20 test/traversal.js
View
@@ -11,9 +11,9 @@ module.exports.built = function(assert) {
assert.equal(doc, doc.root().parent());
assert.equal(child, gchild.parent());
- assert.equal(gchild, doc.child(1).child(0));
+ assert.equal(gchild, doc.child(0).child(0));
- assert.equal(sibling, doc.child(2));
+ assert.equal(sibling, doc.child(1));
assert.done();
};
@@ -27,7 +27,7 @@ module.exports.children = function(assert) {
assert.equal(children.length, doc.childNodes().length);
for (var i = 0; i < children.length; ++i) {
- assert.equal(children[i], doc.child(i+1));
+ assert.equal(children[i], doc.child(i));
}
assert.done();
};
@@ -51,18 +51,18 @@ module.exports.parsed = function(assert) {
'<?xml version="1.0"?>' +
'<root><child><grandchild /></child><sibling/></root>');
assert.equal(doc, doc.child(0).doc());
- assert.equal(doc, doc.child(2).doc());
- assert.equal(doc, doc.child(0).child(1).doc());
+ assert.equal(doc, doc.child(1).doc());
+ assert.equal(doc, doc.child(0).child(0).doc());
assert.equal(doc, doc.root().parent());
// down and back up
assert.equal('child', doc.child(0).child(0).parent().name());
// propertly access inner nodes
- assert.equal('grandchild', doc.child(1).child(0).name());
+ assert.equal('grandchild', doc.child(0).child(0).name());
// sibling nodes
- assert.equal('sibling', doc.child(2).name());
+ assert.equal('sibling', doc.child(1).name());
assert.done();
};
@@ -75,11 +75,11 @@ module.exports.parsed_children = function(assert) {
// childNodes
assert.equal(3, doc.childNodes().length);
for (var i = 0; i < children.length; ++i) {
- assert.equal(children[i], doc.child(i+1).name());
+ assert.equal(children[i], doc.child(i).name());
}
// check prev/next sibling
- var child = doc.child(2);
+ var child = doc.child(1);
assert.equal('child', child.name());
assert.equal(children[0], child.prevSibling().name());
assert.equal(children[2], child.nextSibling().name());
@@ -87,7 +87,7 @@ module.exports.parsed_children = function(assert) {
assert.equal(null, child.nextSibling().nextSibling());
// prev/next Element
- var child = doc.child(2);
+ var child = doc.child(1);
assert.equal('child', child.name());
assert.equal(children[0], child.prevElement().name());
assert.equal(children[2], child.nextElement().name());
Please sign in to comment.
Something went wrong with that request. Please try again.