UNPKG

libxmljs

Version:

libxml bindings for v8 javascript engine

95 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var libxml = require("../index"); module.exports.invalid_new = function (assert) { var doc = libxml.Document(); assert.throws(function () { libxml.Text(); }); assert.throws(function () { libxml.Text(doc); }); assert.done(); }; module.exports.new = function (assert) { var doc = libxml.Document(); var elem = libxml.Text(doc, "node content"); doc.root(elem); assert.equal("node content", elem.text()); assert.done(); }; module.exports.setters = function (assert) { var doc = libxml.Document(); var elem = libxml.Text(doc, "node content"); assert.equal("node content", elem.text()); elem.text("content && more content <>"); assert.equal("content &amp;&amp; more content &lt;&gt;", elem.text()); assert.done(); }; module.exports.remove = function (assert) { var doc = libxml.Document(); var elem = libxml.Text(doc, "node content"); doc.root(elem); assert.equal('<?xml version="1.0" encoding="UTF-8"?>\nnode content\n', doc.toString()); elem.remove(); assert.equal('<?xml version="1.0" encoding="UTF-8"?>\n', doc.toString()); assert.done(); }; module.exports.toString = function (assert) { var doc = libxml.Document(); var elem = libxml.Text(doc, "node content"); doc.root(elem); assert.equal("node content", elem.toString()); assert.done(); }; module.exports.addChild = function (assert) { var doc = libxml.Document(); var newTextNode = libxml.Text(doc, "my text"); var newElement = libxml.Element(doc, "div"); newElement.addChild(newTextNode); doc.root(newElement); assert.equal("<div>my text</div>", newElement.toString()); assert.done(); }; module.exports.addSiblings = function (assert) { var doc = libxml.Document(); var parentNode = libxml.Element(doc, "div"); var child = parentNode.node("child", "i'm a child"); var prevTextNode = libxml.Text(doc, "before text"); var nextTextNode = libxml.Text(doc, "after text"); child.addPrevSibling(prevTextNode); child.addNextSibling(nextTextNode); assert.equal("<div>before text<child>i'm a child</child>after text</div>", parentNode.toString()); assert.done(); }; module.exports.add_prev_sibling_merge_text = function (assert) { var _a, _b, _c; var str = "<foo>bar<baz/></foo>"; var doc = libxml.parseXml(str); var bar = (_a = doc.root()) === null || _a === void 0 ? void 0 : _a.childNodes()[0]; var qux = libxml.Text(doc, "qux"); bar === null || bar === void 0 ? void 0 : bar.addPrevSibling(qux); var children = (_b = doc.root()) === null || _b === void 0 ? void 0 : _b.childNodes(); assert.strictEqual(children === null || children === void 0 ? void 0 : children.length, 2); assert.strictEqual("quxbar", (_c = children === null || children === void 0 ? void 0 : children[0]) === null || _c === void 0 ? void 0 : _c.text()); assert.ok((children === null || children === void 0 ? void 0 : children[0]) != qux); assert.strictEqual(doc, qux.parent()); assert.strictEqual("qux", qux.text()); assert.done(); }; module.exports.add_next_sibling_merge_text = function (assert) { var _a, _b, _c; var str = "<foo>bar<baz/></foo>"; var doc = libxml.parseXml(str); var bar = (_a = doc.root()) === null || _a === void 0 ? void 0 : _a.childNodes()[0]; var qux = libxml.Text(doc, "qux"); bar === null || bar === void 0 ? void 0 : bar.addNextSibling(qux); var children = (_b = doc.root()) === null || _b === void 0 ? void 0 : _b.childNodes(); assert.strictEqual(children === null || children === void 0 ? void 0 : children.length, 2); assert.strictEqual("barqux", (_c = children === null || children === void 0 ? void 0 : children[0]) === null || _c === void 0 ? void 0 : _c.text()); assert.ok((children === null || children === void 0 ? void 0 : children[0]) != qux); assert.strictEqual(doc, qux.parent()); assert.strictEqual("qux", qux.text()); assert.done(); }; //# sourceMappingURL=text.js.map