UNPKG

libxmljs

Version:

libxml bindings for v8 javascript engine

78 lines 4.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var libxml = require("../index"); module.exports.built = function (assert) { var _a, _b, _c; var doc = libxml.Document(); var child = doc.node("root").node("child"); var sibling = (_a = doc.root()) === null || _a === void 0 ? void 0 : _a.node("sibling"); var gchild = child.node("grandchild"); assert.ok(doc == gchild.doc()); assert.ok(doc == ((_b = doc.root()) === null || _b === void 0 ? void 0 : _b.parent())); assert.ok(child == gchild.parent()); assert.ok(gchild == ((_c = doc.child(0)) === null || _c === void 0 ? void 0 : _c.child(0))); assert.ok(sibling == doc.child(1)); assert.done(); }; module.exports.children = function (assert) { var children = []; var doc = libxml.Document(); var root = doc.node("root"); children.push(root.node("child")); children.push(root.node("sibling1")); children.push(root.node("sibling2")); assert.equal(children.length, doc.childNodes().length); for (var i = 0; i < children.length; ++i) { assert.ok(children[i] == doc.child(i)); } assert.done(); }; module.exports.siblings = function (assert) { var _a, _b, _c, _d; var children = []; var doc = libxml.Document(); var root = doc.node("root"); children.push(root.node("prevSibling")); children.push(root.node("child")); children.push(root.node("nextSibling")); assert.ok(children[0] == ((_a = children[1]) === null || _a === void 0 ? void 0 : _a.prevSibling())); assert.ok(children[2] == ((_b = children[1]) === null || _b === void 0 ? void 0 : _b.nextSibling())); assert.ok(null == ((_c = children[0]) === null || _c === void 0 ? void 0 : _c.prevSibling())); assert.ok(null == ((_d = children[2]) === null || _d === void 0 ? void 0 : _d.nextSibling())); assert.done(); }; module.exports.parsed = function (assert) { var _a, _b, _c, _d, _e, _f, _g, _h; var doc = libxml.parseXml('<?xml version="1.0"?>' + "<root><child><grandchild /></child><sibling/></root>"); assert.ok(doc == doc.child(0).doc()); assert.ok(doc == doc.child(1).doc()); assert.ok(doc == ((_a = doc.child(0)) === null || _a === void 0 ? void 0 : _a.child(0)).doc()); assert.ok(doc == ((_b = doc.root()) === null || _b === void 0 ? void 0 : _b.parent())); assert.equal("child", (_e = (_d = (_c = doc.child(0)) === null || _c === void 0 ? void 0 : _c.child(0)) === null || _d === void 0 ? void 0 : _d.parent()) === null || _e === void 0 ? void 0 : _e.name()); assert.equal("grandchild", (_g = (_f = doc.child(0)) === null || _f === void 0 ? void 0 : _f.child(0)) === null || _g === void 0 ? void 0 : _g.name()); assert.equal("sibling", (_h = doc.child(1)) === null || _h === void 0 ? void 0 : _h.name()); assert.done(); }; module.exports.parsed_children = function (assert) { var _a, _b, _c, _d, _e, _f, _g, _h; var doc = libxml.parseXml('<?xml version="1.0"?>' + "<root><prevSibling /><child /><nextSibling /></root>"); var children = ["prevSibling", "child", "nextSibling"]; assert.ok(3 == doc.childNodes().length); for (var i = 0; i < children.length; ++i) { assert.ok(children[i] == doc.child(i).name()); } var child = doc.child(1); assert.equal("child", child.name()); assert.equal(children[0], (_a = child.prevSibling()) === null || _a === void 0 ? void 0 : _a.name()); assert.equal(children[2], (_b = child.nextSibling()) === null || _b === void 0 ? void 0 : _b.name()); assert.ok(null == ((_c = child.prevSibling()) === null || _c === void 0 ? void 0 : _c.prevSibling())); assert.ok(null == ((_d = child.nextSibling()) === null || _d === void 0 ? void 0 : _d.nextSibling())); var child = doc.child(1); assert.equal("child", child.name()); assert.equal(children[0], (_e = child.prevElement()) === null || _e === void 0 ? void 0 : _e.name()); assert.equal(children[2], (_f = child.nextElement()) === null || _f === void 0 ? void 0 : _f.name()); assert.ok(null == ((_g = child.prevElement()) === null || _g === void 0 ? void 0 : _g.prevElement())); assert.ok(null == ((_h = child.nextElement()) === null || _h === void 0 ? void 0 : _h.nextElement())); assert.done(); }; //# sourceMappingURL=traversal.js.map