Comparing version 0.4.2 to 0.4.3
@@ -5,3 +5,3 @@ { "name" : "libxmljs" | ||
, "description" : "libxml bindings for v8 javascript engine" | ||
, "version" : "0.4.2" | ||
, "version" : "0.4.3" | ||
, "scripts" : | ||
@@ -18,3 +18,3 @@ { "preinstall" : "make node" | ||
{ "mail" : "" | ||
, "web" : "http://github.com/polotek/libxmljs/issues" | ||
, "url" : "http://github.com/polotek/libxmljs/issues" | ||
} | ||
@@ -21,0 +21,0 @@ , "main" : "./libxmljs" |
# Libxmljs | ||
LibXML bindings for Google's v8 javascript engine. | ||
LibXML bindings for [node.js](http://nodejs.org/) | ||
It also plays nicely with [[node.js|http://nodejs.org/]] | ||
var libxmljs = require("libxmljs"); | ||
var xml = '<?xml version="1.0" encoding="UTF-8"?>' + | ||
'<root>' + | ||
'<child foo="bar">' + | ||
'<grandchild baz="fizbuzz">grandchild content</grandchild>' + | ||
'</child>' + | ||
'<sibling>with content!</sibling>' + | ||
'</root>'; | ||
var xmlDoc = libxmljs.parseXmlString(xml); | ||
// xpath queries | ||
var gchild = xmlDoc.get('//grandchild'); | ||
console.log(gchild.text()); // prints "grandchild content" | ||
var children = xmlDoc.root().childNodes(); | ||
var child = children[0]; | ||
console.log(child.attr('foo').value()); // prints "bar" | ||
## Basics | ||
* GitHub Repo - [[http://github.com/polotek/libxmljs]] | ||
* Docs - [[http://github.com/polotek/libxmljs/wiki]] | ||
* Mailing list - [[http://groups.google.com/group/libxmljs]] | ||
* GitHub Repo - [http://github.com/polotek/libxmljs](http://github.com/polotek/libxmljs) | ||
* Docs - [http://github.com/polotek/libxmljs/wiki](http://github.com/polotek/libxmljs/wiki) | ||
* Mailing list - [http://groups.google.com/group/libxmljs](http://groups.google.com/group/libxmljs) | ||
## API | ||
## API and Examples | ||
Some examples below or check out the full [[http://github.com/polotek/libxmljs/wiki]] | ||
Check out the wiki [http://github.com/polotek/libxmljs/wiki](http://github.com/polotek/libxmljs/wiki) | ||
## Requirements | ||
* libxml | ||
* v8 (for the standalone version) | ||
* node.js (for the node.js version, v8 comes bundled) | ||
* [libxml2](http://www.xmlsoft.org/) | ||
* [node.js](http://nodejs.org/) | ||
* v8 (comes bundled with node, no need to install) | ||
* [scons](http://www.scons.org/) (for building) | ||
## Building | ||
**pre-conditions** | ||
To build the node.js plugin use: | ||
You will need have the libxml2 library installed and also the libxml2-devel | ||
package. This comes with the `xml2-config` utility that is needed for | ||
compiling. **This command must be in your path.** | ||
make libxmljs.node | ||
The `scons` command is used for building and must also be in your path. | ||
To run tests: | ||
## Installation | ||
**npm** | ||
npm install libxmljs | ||
**source** | ||
In the root of the source directory, just run `make`. This will | ||
generate the binary `libxmljs.node` in the root of the source folder. | ||
You can copy this file to `~/.node_libraries` or any other directory | ||
in your require path. | ||
**tests** | ||
make test | ||
make test-verbose |
@@ -0,1 +1,3 @@ | ||
exports.gc = (typeof gc == 'undefined') ? function() {} : gc; | ||
exports.libxml = require('../libxmljs'); | ||
@@ -2,0 +4,0 @@ |
@@ -16,4 +16,4 @@ with(require('./helpers')) { | ||
var attr = new libxml.Attribute(node, 'new-attr-key', 'new-attr-value'); | ||
assert(attr); | ||
assertEqual(attr.value(), node.attr('new-attr-key').value()); | ||
assert.ok(attr); | ||
assert.equal(attr.value(), node.attr('new-attr-key').value()); | ||
}); | ||
@@ -24,17 +24,17 @@ | ||
var attr = new libxml.Attribute(node, 'new-attr-key', 'new-attr-value', ns); | ||
assert(attr); | ||
assertEqual(ns.prefix(), attr.namespace().prefix()); | ||
assertEqual(ns.href(), attr.namespace().href()); | ||
assert.ok(attr); | ||
assert.equal(ns.prefix(), attr.namespace().prefix()); | ||
assert.equal(ns.href(), attr.namespace().href()); | ||
}); | ||
it('knows its name', function() { | ||
assertEqual('attr-one-key', node.attr('attr-one-key').name()); | ||
assert.equal('attr-one-key', node.attr('attr-one-key').name()); | ||
}); | ||
it('knows its value', function() { | ||
assertEqual('attr-one-value', node.attr('attr-one-key').value()); | ||
assert.equal('attr-one-value', node.attr('attr-one-key').value()); | ||
}); | ||
it('knows its node', function() { | ||
assertEqual('node', node.attr('attr-one-key').node().name()); | ||
assert.equal('node', node.attr('attr-one-key').node().name()); | ||
}); | ||
@@ -44,11 +44,11 @@ | ||
node.attr('attr-one-key').value('new-value'); | ||
assertEqual(node.attr('attr-one-key').value(), 'new-value'); | ||
assert.equal(node.attr('attr-one-key').value(), 'new-value'); | ||
}); | ||
it('knows its previous sibling', function() { | ||
assertEqual('attr-one-key', node.attr('attr-two-key').prevSibling().name()); | ||
assert.equal('attr-one-key', node.attr('attr-two-key').prevSibling().name()); | ||
}); | ||
it('knows its next sibling', function() { | ||
assertEqual('attr-three-key', node.attr('attr-two-key').nextSibling().name()); | ||
assert.equal('attr-three-key', node.attr('attr-two-key').nextSibling().name()); | ||
}); | ||
@@ -60,8 +60,8 @@ | ||
attr.namespace(ns); | ||
assertEqual(ns.prefix(), attr.namespace().prefix()); | ||
assertEqual(ns.href(), attr.namespace().href()); | ||
assert.equal(ns.prefix(), attr.namespace().prefix()); | ||
assert.equal(ns.href(), attr.namespace().href()); | ||
}); | ||
it('knows that its type is "attribute"', function() { | ||
assert('attribute', node.attr('attr-two-key').type()); | ||
assert.ok('attribute', node.attr('attr-two-key').type()); | ||
}); | ||
@@ -71,5 +71,5 @@ | ||
var attr = node.attr('attr-one-key'); | ||
assert(node.attr('attr-one-key')); | ||
assert.ok(node.attr('attr-one-key')); | ||
attr.remove(); | ||
assert(!node.attr('attr-one-key')); | ||
assert.ok(!node.attr('attr-one-key')); | ||
}); | ||
@@ -76,0 +76,0 @@ }); |
@@ -6,5 +6,5 @@ with(require('./helpers')) { | ||
var doc = new libxml.Document(); | ||
assert(doc); | ||
assertEqual('1.0', doc.version()); | ||
assertEqual(null, doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('1.0', doc.version()); | ||
assert.equal(null, doc.encoding()); | ||
}); | ||
@@ -14,5 +14,5 @@ | ||
var doc = new libxml.Document('2.0'); | ||
assert(doc); | ||
assertEqual('2.0', doc.version()); | ||
assertEqual(null, doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('2.0', doc.version()); | ||
assert.equal(null, doc.encoding()); | ||
}); | ||
@@ -22,5 +22,5 @@ | ||
var doc = new libxml.Document('2.0', 'UTF-8'); | ||
assert(doc); | ||
assertEqual('2.0', doc.version()); | ||
assertEqual('UTF-8', doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('2.0', doc.version()); | ||
assert.equal('UTF-8', doc.encoding()); | ||
}); | ||
@@ -31,5 +31,5 @@ | ||
new libxml.Document(function(d) { doc = d; }); | ||
assert(doc); | ||
assertEqual('1.0', doc.version()); | ||
assertEqual(null, doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('1.0', doc.version()); | ||
assert.equal(null, doc.encoding()); | ||
}); | ||
@@ -40,5 +40,5 @@ | ||
new libxml.Document('2.0', function(d) { doc = d; }); | ||
assert(doc); | ||
assertEqual('2.0', doc.version()); | ||
assertEqual(null, doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('2.0', doc.version()); | ||
assert.equal(null, doc.encoding()); | ||
}); | ||
@@ -49,5 +49,5 @@ | ||
new libxml.Document('2.0', 'UTF-8', function(d) { doc = d; }); | ||
assert(doc); | ||
assertEqual('2.0', doc.version()); | ||
assertEqual('UTF-8', doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal('2.0', doc.version()); | ||
assert.equal('UTF-8', doc.encoding()); | ||
}); | ||
@@ -57,3 +57,3 @@ | ||
var doc = new libxml.Document(); | ||
assertEqual(null, doc.root()); | ||
assert.equal(null, doc.root()); | ||
}); | ||
@@ -64,4 +64,4 @@ | ||
var root = doc.node('root'); | ||
assertEqual('root', root.name()); | ||
assertEqual(root, doc.root()); | ||
assert.equal('root', root.name()); | ||
assert.equal(root, doc.root()); | ||
}); | ||
@@ -72,4 +72,4 @@ | ||
doc.node('root').node('child-one').parent().node('child-two'); | ||
assertEqual('child-one', doc.child(1).name()); | ||
assertEqual('child-two', doc.child(2).name()); | ||
assert.equal('child-one', doc.child(1).name()); | ||
assert.equal('child-two', doc.child(2).name()); | ||
}); | ||
@@ -80,4 +80,4 @@ | ||
doc.node('root').node('child-one').parent().node('child-two'); | ||
assertEqual('child-one', doc.childNodes()[0].name()); | ||
assertEqual('child-two', doc.childNodes()[1].name()); | ||
assert.equal('child-one', doc.childNodes()[0].name()); | ||
assert.equal('child-two', doc.childNodes()[1].name()); | ||
}); | ||
@@ -87,3 +87,3 @@ | ||
var doc = new libxml.Document(); | ||
assertEqual(doc, doc.document()); | ||
assert.equal(doc, doc.document()); | ||
}); | ||
@@ -93,6 +93,6 @@ | ||
var doc = new libxml.Document(); | ||
assert(doc); | ||
assertEqual(null, doc.encoding()); | ||
assert.ok(doc); | ||
assert.equal(null, doc.encoding()); | ||
doc.encoding('UTF-8'); | ||
assertEqual('UTF-8', doc.encoding()); | ||
assert.equal('UTF-8', doc.encoding()); | ||
}); | ||
@@ -103,3 +103,3 @@ | ||
doc.node('root').node('child').parent().node('child'); | ||
assertEqual(2, doc.find('child').length); | ||
assert.equal(2, doc.find('child').length); | ||
}); | ||
@@ -110,4 +110,4 @@ | ||
doc.node('root').node('child-one').parent().node('child-two'); | ||
assertEqual('child-one', doc.get('child-one').name()); | ||
assertEqual('child-two', doc.get('child-two').name()); | ||
assert.equal('child-one', doc.get('child-one').name()); | ||
assert.equal('child-two', doc.get('child-two').name()); | ||
}); | ||
@@ -118,3 +118,3 @@ | ||
doc.node('root').node('child').parent().node('child'); | ||
assertEqual(doc.root().name(), doc.get('/root').name()); | ||
assert.equal(doc.root().name(), doc.get('/root').name()); | ||
}); | ||
@@ -137,6 +137,58 @@ | ||
}); | ||
assertEqual(control, doc.toString()); | ||
assert.equal(control, doc.toString()); | ||
}); | ||
it('can add child nodes', function() { | ||
var gchild = ''; | ||
var doc1_string = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<root><child to="wongfoo"><grandchild from="julie numar">with love</grandchild></child><sibling>with content!</sibling></root>', | ||
'' | ||
].join("\n"); | ||
var doc2_string = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<root><child to="wongfoo"></child><sibling>with content!</sibling></root>', | ||
'' | ||
].join("\n"); | ||
var doc1 = libxml.parseXmlString(doc1_string); | ||
var doc2 = libxml.parseXmlString(doc2_string); | ||
doc2.child(0).addChild(doc1.child(0).child(0)); | ||
assert.equal(doc1.toString(), doc2.toString()); | ||
}); | ||
it('can add a cloned node', function() { | ||
var gchild_string = '<grandchild from="julie numar">with love</grandchild>'; | ||
var doc1_string = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<root><child to="wongfoo">'+gchild_string+'</child><sibling>with content!</sibling></root>', | ||
'' | ||
].join("\n"); | ||
var doc2_string = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<root><child to="wongfoo"/><sibling>with content!</sibling></root>', | ||
'' | ||
].join("\n"); | ||
var doc1 = libxml.parseXmlString(doc1_string); | ||
var doc2 = libxml.parseXmlString(doc2_string); | ||
var gchild = doc1.child(0).child(0); //the element to operate on | ||
doc2.child(0).addChild(gchild); // add gchild clone to doc2, implicit clone | ||
assert.equal(doc1.toString(), doc2.toString()); // both documents should be the same | ||
assert. notEqual(gchild, doc2.child(0).child(0)); // these nodes should be different (cloned) | ||
gchild.remove(); | ||
assert.equal(doc2_string, doc1.toString()); //doc1 should be the same as doc2 str | ||
assert.equal(doc1_string, doc2.toString()); //doc2 should be the same as doc1 str | ||
}); | ||
}); | ||
} |
@@ -13,3 +13,3 @@ with(require('./helpers')) { | ||
it('can be created', function() { | ||
assertEqual('name1', elem.name()); | ||
assert.equal('name1', elem.name()); | ||
}); | ||
@@ -21,7 +21,7 @@ | ||
doc.node('name2', function(n) { elem = n; }); | ||
assertEqual('name2', elem.name()); | ||
assert.equal('name2', elem.name()); | ||
}); | ||
it('can be created as the document root', function() { | ||
assertEqual('name1', doc.root().name()); | ||
assert.equal('name1', doc.root().name()); | ||
}); | ||
@@ -34,23 +34,23 @@ | ||
levels++; | ||
assertEqual('root', n.name()); | ||
assert.equal('root', n.name()); | ||
n.node('child', function(n) { | ||
levels++; | ||
assertEqual('child', n.name()); | ||
assert.equal('child', n.name()); | ||
var grandchild = n.node('grandchild', function() { levels++; }); | ||
assertEqual('grandchild', grandchild.name()); | ||
assert.equal('grandchild', grandchild.name()); | ||
}); | ||
}); | ||
assertEqual(3, levels); | ||
assert.equal(3, levels); | ||
}); | ||
it('can have content assigned after creation', function() { | ||
assertEqual("", elem.text()); | ||
assert.equal("", elem.text()); | ||
elem.text('content'); | ||
assertEqual('content', elem.text()); | ||
assert.equal('content', elem.text()); | ||
}); | ||
it('can undergo a namechange after creation', function() { | ||
assertEqual('name1', elem.name()); | ||
assert.equal('name1', elem.name()); | ||
elem.name('newname'); | ||
assertEqual('newname', elem.name()); | ||
assert.equal('newname', elem.name()); | ||
}); | ||
@@ -61,3 +61,3 @@ | ||
elem.addChild(newChild); | ||
assert(doc.get('/name1/new-child')); | ||
assert.ok(doc.get('/name1/new-child')); | ||
}); | ||
@@ -75,14 +75,14 @@ | ||
}); | ||
assertEqual('/root/child[1]/grandchild', gchild.path()); | ||
assertEqual('/root/child[2]', sibling.path()); | ||
assert.equal('/root/child[1]/grandchild', gchild.path()); | ||
assert.equal('/root/child[2]', sibling.path()); | ||
}); | ||
it('knows that its type is "element"', function() { | ||
assert('element', elem.type()); | ||
assert.ok('element', elem.type()); | ||
}); | ||
it('can print itself using #toString', function() { | ||
assertEqual('<name1/>', elem.toString()); | ||
assert.equal('<name1/>', elem.toString()); | ||
elem.node('child'); | ||
assertEqual('<name1><child/></name1>', elem.toString()); | ||
assert.equal('<name1><child/></name1>', elem.toString()); | ||
}); | ||
@@ -92,6 +92,6 @@ | ||
var child = elem.node('child'); | ||
assert(doc.get('/name1/child')); | ||
assert.ok(doc.get('/name1/child')); | ||
child.remove(); | ||
assert(!doc.get('/name1/child')); | ||
assert.ok(!doc.get('/name1/child')); | ||
}); | ||
@@ -101,3 +101,3 @@ | ||
var child = elem.node('child'); | ||
assert(doc.get('/name1/child')); | ||
assert.ok(doc.get('/name1/child')); | ||
@@ -107,4 +107,4 @@ child.remove(); | ||
name2.node(child); | ||
assert(!doc.get('/name1/child')); | ||
assert(doc.get('/name1/name2/child')); | ||
assert.ok(!doc.get('/name1/child')); | ||
assert.ok(doc.get('/name1/name2/child')); | ||
}); | ||
@@ -115,8 +115,8 @@ | ||
var child2 = elem.node('child2'); | ||
assertEqual(elem.childNodes().length, 2); | ||
assert.equal(elem.childNodes().length, 2); | ||
var prevSibling = new libxml.Element(elem.doc(), 'prev-sibling'); | ||
var addedSibling = child2.addPrevSibling(prevSibling); | ||
var children = elem.childNodes(); | ||
assertEqual(3, children.length); | ||
assertEqual('prev-sibling', children[1].name()); | ||
assert.equal(3, children.length); | ||
assert.equal('prev-sibling', children[1].name()); | ||
}); | ||
@@ -127,11 +127,26 @@ | ||
var child2 = elem.node('child2'); | ||
assertEqual(elem.childNodes().length, 2); | ||
assert.equal(elem.childNodes().length, 2); | ||
var nextSibling = new libxml.Element(elem.doc(), 'next-sibling'); | ||
var addedSibling = child1.addNextSibling(nextSibling); | ||
var children = elem.childNodes(); | ||
assertEqual(3, children.length); | ||
assertEqual('next-sibling', children[1].name()); | ||
assert.equal(3, children.length); | ||
assert.equal('next-sibling', children[1].name()); | ||
}); | ||
it('can be imported to another document', function() { | ||
var child1 = elem.node('child1'); | ||
doc = child1.doc(); | ||
var newdoc = new libxml.Document(); | ||
newdoc.node('newdoc'); | ||
newdoc.root().addChild(child1); | ||
assert.ok(newdoc); | ||
assert. notEqual(doc, newdoc, true); | ||
assert.equal('child1', newdoc.root().childNodes()[0].name()); | ||
gc(); | ||
assert.equal(child1, elem.childNodes()[0]); // child1 is the the first child of elem | ||
}); | ||
}); | ||
} |
@@ -58,5 +58,5 @@ with(require('./helpers')) { | ||
var doc = libxml.parseHtmlString(str); | ||
assertEqual('html', doc.root().name()); | ||
assertEqual('Test HTML document', doc.get('head/title').text()); | ||
assertEqual('HTML content!', doc.get('body/span').text()); | ||
assert.equal('html', doc.root().name()); | ||
assert.equal('Test HTML document', doc.get('head/title').text()); | ||
assert.equal('HTML content!', doc.get('body/span').text()); | ||
}); | ||
@@ -66,5 +66,5 @@ | ||
var doc = libxml.parseHtmlFile(filename); | ||
assertEqual('html', doc.root().name()); | ||
assertEqual('Test HTML document', doc.get('head/title').text()); | ||
assertEqual('HTML content!', doc.get('body/span').text()); | ||
assert.equal('html', doc.root().name()); | ||
assert.equal('Test HTML document', doc.get('head/title').text()); | ||
assert.equal('HTML content!', doc.get('body/span').text()); | ||
}); | ||
@@ -76,4 +76,4 @@ }); | ||
var doc = libxml.parseHtmlFile(recoverableFile); | ||
assertEqual(4, doc.errors().length); | ||
assertEqual(recoverableErrors, doc.errors()); | ||
assert.equal(4, doc.errors().length); | ||
assert.deepEqual(recoverableErrors, doc.errors()); | ||
}); | ||
@@ -87,6 +87,6 @@ }); | ||
var doc = libxml.parseHtmlString(str); | ||
assertEqual(4, doc.errors().length); | ||
assert.equal(4, doc.errors().length); | ||
for (var i in recoverableErrors) | ||
recoverableErrors[i].file = null; | ||
assertEqual(recoverableErrors, doc.errors()); | ||
assert.deepEqual(recoverableErrors, doc.errors()); | ||
}); | ||
@@ -93,0 +93,0 @@ }); |
@@ -6,3 +6,3 @@ with(require('./helpers')) { | ||
if (specVerbose) print(libxml.version+" "); | ||
assert(typeof libxml.version == 'string'); | ||
assert.ok(typeof libxml.version == 'string'); | ||
}); | ||
@@ -12,3 +12,3 @@ | ||
if (specVerbose) print(libxml.libxml_version+" "); | ||
assert(typeof libxml.libxml_version == 'string'); | ||
assert.ok(typeof libxml.libxml_version == 'string'); | ||
}); | ||
@@ -18,3 +18,3 @@ | ||
if (specVerbose) print(libxml.libxml_parser_version+" "); | ||
assert(typeof libxml.libxml_parser_version == 'string'); | ||
assert.ok(typeof libxml.libxml_parser_version == 'string'); | ||
}); | ||
@@ -24,3 +24,3 @@ | ||
if (specVerbose) print(libxml.libxml_debug_enabled+" "); | ||
assert(typeof libxml.libxml_debug_enabled == 'boolean'); | ||
assert.ok(typeof libxml.libxml_debug_enabled == 'boolean'); | ||
}); | ||
@@ -27,0 +27,0 @@ }); |
@@ -8,5 +8,5 @@ with(require('./helpers')) { | ||
var ns = elem.defineNamespace('http://my-namespace.com'); | ||
assertEqual(null, elem.namespace()); | ||
assertEqual(null, ns.prefix()); | ||
assertEqual('http://my-namespace.com', ns.href()); | ||
assert.equal(null, elem.namespace()); | ||
assert.equal(null, ns.prefix()); | ||
assert.equal('http://my-namespace.com', ns.href()); | ||
}); | ||
@@ -18,5 +18,5 @@ | ||
var ns = elem.defineNamespace('pref', 'http://my-namespace.com'); | ||
assertEqual(null, elem.namespace()); | ||
assertEqual('pref', ns.prefix()); | ||
assertEqual('http://my-namespace.com', ns.href()); | ||
assert.equal(null, elem.namespace()); | ||
assert.equal('pref', ns.prefix()); | ||
assert.equal('http://my-namespace.com', ns.href()); | ||
}); | ||
@@ -28,5 +28,5 @@ | ||
var ns = elem.namespace('http://my-namespace.com'); | ||
assert(ns == elem.namespace()); | ||
assertEqual(null, elem.namespace().prefix()); | ||
assertEqual('http://my-namespace.com', elem.namespace().href()); | ||
assert.ok(ns == elem.namespace()); | ||
assert.equal(null, elem.namespace().prefix()); | ||
assert.equal('http://my-namespace.com', elem.namespace().href()); | ||
}); | ||
@@ -38,5 +38,5 @@ | ||
var ns = elem.namespace('pref', 'http://my-namespace.com'); | ||
assert(ns == elem.namespace()); | ||
assertEqual('pref', elem.namespace().prefix()); | ||
assertEqual('http://my-namespace.com', elem.namespace().href()); | ||
assert.ok(ns == elem.namespace()); | ||
assert.equal('pref', elem.namespace().prefix()); | ||
assert.equal('http://my-namespace.com', elem.namespace().href()); | ||
}); | ||
@@ -48,5 +48,5 @@ | ||
var elem = doc.root(); | ||
assert(elem.namespace()); | ||
assertEqual(null, elem.namespace().prefix()); | ||
assertEqual('http://my-namespace.com', elem.namespace().href()); | ||
assert.ok(elem.namespace()); | ||
assert.equal(null, elem.namespace().prefix()); | ||
assert.equal('http://my-namespace.com', elem.namespace().href()); | ||
}); | ||
@@ -58,3 +58,3 @@ | ||
var elem = doc.root(); | ||
assert(!elem.namespace()); | ||
assert.ok(!elem.namespace()); | ||
}); | ||
@@ -66,5 +66,5 @@ | ||
var elem = doc.root(); | ||
assert(elem.namespace()); | ||
assertEqual('pref', elem.namespace().prefix()); | ||
assertEqual('http://my-namespace.com', elem.namespace().href()); | ||
assert.ok(elem.namespace()); | ||
assert.equal('pref', elem.namespace().prefix()); | ||
assert.equal('http://my-namespace.com', elem.namespace().href()); | ||
}); | ||
@@ -77,3 +77,3 @@ | ||
elem.namespace('http://my-namespace.com'); | ||
assert(ns == elem.namespace()); | ||
assert.ok(ns == elem.namespace()); | ||
}); | ||
@@ -86,3 +86,3 @@ | ||
elem.namespace('pref', 'http://my-namespace.com'); | ||
assert(ns == elem.namespace()); | ||
assert.ok(ns == elem.namespace()); | ||
}); | ||
@@ -94,6 +94,6 @@ | ||
var ns = elem.namespace('http://my-namespace.com'); | ||
assert(ns); | ||
assert(ns == elem.namespace()); | ||
assert.ok(ns); | ||
assert.ok(ns == elem.namespace()); | ||
elem.namespace(null); | ||
assert(!elem.namespace()); | ||
assert.ok(!elem.namespace()); | ||
}); | ||
@@ -100,0 +100,0 @@ }); |
@@ -9,3 +9,3 @@ with(require('./helpers')) { | ||
new libxml.Attribute(elem, 'to', 'wongfoo'); | ||
assertEqual('wongfoo', elem.attr('to').value()); | ||
assert.equal('wongfoo', elem.attr('to').value()); | ||
}); | ||
@@ -16,3 +16,3 @@ | ||
elem = doc.node('name'); | ||
assertEqual(null, elem.attr('to')); | ||
assert.equal(null, elem.attr('to')); | ||
}); | ||
@@ -23,3 +23,3 @@ | ||
var elem = doc.node('name', {to: 'wongfoo'}); | ||
assertEqual('wongfoo', elem.attr('to').value()); | ||
assert.equal('wongfoo', elem.attr('to').value()); | ||
}); | ||
@@ -31,3 +31,3 @@ | ||
elem.attr({to: 'wongfoo'}); | ||
assertEqual('wongfoo', elem.attr('to').value()); | ||
assert.equal('wongfoo', elem.attr('to').value()); | ||
}); | ||
@@ -38,5 +38,5 @@ | ||
var elem = doc.node('name', {to: 'wongfoo'}); | ||
assertEqual('wongfoo', elem.attr('to').value()); | ||
assert.equal('wongfoo', elem.attr('to').value()); | ||
elem.attr({to: 'julie newmar'}); | ||
assertEqual('julie newmar', elem.attr('to').value()); | ||
assert.equal('julie newmar', elem.attr('to').value()); | ||
}); | ||
@@ -48,3 +48,3 @@ | ||
assertEqual([], elem.attrs()); | ||
assert.deepEqual([], elem.attrs()); | ||
@@ -58,3 +58,3 @@ elem.attr({foo: 'bar'}) | ||
for (i = 0; i < 3; i++) | ||
assertEqual(attrs[i], elem.attrs()[i]); | ||
assert.equal(attrs[i], elem.attrs()[i]); | ||
}); | ||
@@ -68,6 +68,6 @@ | ||
.attr({baz: 'foo'}); | ||
assertEqual(elem.attr('baz'), elem.attr('bar').nextSibling()); | ||
assertEqual(elem.attr('foo'), elem.attr('bar').prevSibling()); | ||
assertEqual(null, elem.attr('foo').prevSibling()); | ||
assertEqual(null, elem.attr('baz').nextSibling()); | ||
assert.equal(elem.attr('baz'), elem.attr('bar').nextSibling()); | ||
assert.equal(elem.attr('foo'), elem.attr('bar').prevSibling()); | ||
assert.equal(null, elem.attr('foo').prevSibling()); | ||
assert.equal(null, elem.attr('baz').nextSibling()); | ||
}); | ||
@@ -79,3 +79,3 @@ | ||
.attr({foo: 'bar'}); | ||
assertEqual(elem, elem.attr('foo').parent()); | ||
assert.equal(elem, elem.attr('foo').parent()); | ||
}); | ||
@@ -87,3 +87,3 @@ | ||
.attr({foo: 'bar'}); | ||
assertEqual(doc, elem.attr('foo').doc()); | ||
assert.equal(doc, elem.attr('foo').doc()); | ||
}); | ||
@@ -90,0 +90,0 @@ }); |
@@ -9,3 +9,3 @@ with(require('./helpers')) { | ||
}); | ||
assertEqual(child, doc.get('child')); | ||
assert.equal(child, doc.get('child')); | ||
}); | ||
@@ -21,6 +21,6 @@ | ||
var results = doc.find('child'); | ||
assertEqual(2, children.length); | ||
assertEqual(2, results.length); | ||
assert.equal(2, children.length); | ||
assert.equal(2, results.length); | ||
for (child = 0; child < children.length; child++) | ||
assertEqual(children[child], results[child]); | ||
assert.equal(children[child], results[child]); | ||
}); | ||
@@ -36,3 +36,3 @@ | ||
}); | ||
assertEqual(grandchild, doc.get('child').get('grandchild')); | ||
assert.equal(grandchild, doc.get('child').get('grandchild')); | ||
}); | ||
@@ -53,3 +53,3 @@ }); | ||
assertEqual(child, doc.get('xmlns:child', uri)); | ||
assert.equal(child, doc.get('xmlns:child', uri)); | ||
}); | ||
@@ -69,6 +69,6 @@ | ||
var results = doc.find('xmlns:child', uri); | ||
assertEqual(2, children.length); | ||
assertEqual(2, results.length); | ||
assert.equal(2, children.length); | ||
assert.equal(2, results.length); | ||
for (child = 0; child < children.length; child++) | ||
assertEqual(children[child], results[child]); | ||
assert.equal(children[child], results[child]); | ||
}); | ||
@@ -86,3 +86,3 @@ | ||
assertEqual(grandchild, doc.get('child').get('xmlns:grandchild', uri)); | ||
assert.equal(grandchild, doc.get('child').get('xmlns:grandchild', uri)); | ||
}); | ||
@@ -107,3 +107,3 @@ }); | ||
assertEqual(child, doc.get(prefix+':child', ns_parms)); | ||
assert.equal(child, doc.get(prefix+':child', ns_parms)); | ||
}); | ||
@@ -123,6 +123,6 @@ | ||
var results = doc.find(prefix+':child', ns_parms); | ||
assertEqual(2, children.length); | ||
assertEqual(2, results.length); | ||
assert.equal(2, children.length); | ||
assert.equal(2, results.length); | ||
for (child = 0; child < children.length; child++) | ||
assertEqual(children[child], results[child]); | ||
assert.equal(children[child], results[child]); | ||
}); | ||
@@ -140,3 +140,3 @@ | ||
assertEqual(grandchild, | ||
assert.equal(grandchild, | ||
doc.get('child').get(prefix+':grandchild', ns_parms)); | ||
@@ -143,0 +143,0 @@ }); |
@@ -14,7 +14,7 @@ with(require('./helpers')) { | ||
it('knows its type is "text"', function() { | ||
assertEqual('text', doc.child().type()); | ||
assert.equal('text', doc.child().type()); | ||
}); | ||
it('knows its name is "text"', function() { | ||
assertEqual('text', doc.child().name()); | ||
assert.equal('text', doc.child().name()); | ||
}); | ||
@@ -34,7 +34,7 @@ }); | ||
it('knows its type is "comment"', function() { | ||
assertEqual('comment', doc.child().type()); | ||
assert.equal('comment', doc.child().type()); | ||
}); | ||
it('knows its name is "comment"', function() { | ||
assertEqual('comment', doc.child().name()); | ||
assert.equal('comment', doc.child().name()); | ||
}); | ||
@@ -54,7 +54,7 @@ }); | ||
it('knows its type is "cdata"', function() { | ||
assertEqual('cdata', doc.child().type()); | ||
assert.equal('cdata', doc.child().type()); | ||
}); | ||
it('has no name', function() { | ||
assertEqual(undefined, doc.child().name()); | ||
assert.equal(undefined, doc.child().name()); | ||
}); | ||
@@ -61,0 +61,0 @@ }); |
@@ -14,3 +14,3 @@ with(require('./helpers')) { | ||
assertEqual(doc, gchild.doc()); | ||
assert.equal(doc, gchild.doc()); | ||
}); | ||
@@ -28,3 +28,3 @@ | ||
// uses the specific and default syntax for returning a child. | ||
assertEqual(gchild, doc.child(1).child()); | ||
assert.equal(gchild, doc.child(1).child()); | ||
}); | ||
@@ -40,3 +40,3 @@ | ||
}); | ||
assertEqual(sibling, doc.child(2)); | ||
assert.equal(sibling, doc.child(2)); | ||
}); | ||
@@ -53,4 +53,4 @@ | ||
}); | ||
assertEqual(doc, doc.root().parent()); | ||
assertEqual(child, gchild.parent()); | ||
assert.equal(doc, doc.root().parent()); | ||
assert.equal(child, gchild.parent()); | ||
}); | ||
@@ -68,5 +68,5 @@ | ||
var i; | ||
assertEqual(children.length, doc.childNodes().length); | ||
assert.equal(children.length, doc.childNodes().length); | ||
for (i = 0; i < children.length; i++) | ||
assertEqual(children[i], doc.child(i+1)); | ||
assert.equal(children[i], doc.child(i+1)); | ||
}); | ||
@@ -83,6 +83,6 @@ | ||
}); | ||
assertEqual(children[0], children[1].prevSibling()); | ||
assertEqual(children[2], children[1].nextSibling()); | ||
assertEqual(null, children[0].prevSibling()); | ||
assertEqual(null, children[2].nextSibling()); | ||
assert.equal(children[0], children[1].prevSibling()); | ||
assert.equal(children[2], children[1].nextSibling()); | ||
assert.equal(null, children[0].prevSibling()); | ||
assert.equal(null, children[2].nextSibling()); | ||
}); | ||
@@ -97,3 +97,3 @@ }); | ||
'); | ||
assertEqual(doc, doc.child(0).child(1).doc()); | ||
assert.equal(doc, doc.child(0).child(1).doc()); | ||
}); | ||
@@ -107,3 +107,3 @@ | ||
// uses the specific and default syntax for returning a child. | ||
assertEqual('grandchild', doc.child(1).child().name()); | ||
assert.equal('grandchild', doc.child(1).child().name()); | ||
}); | ||
@@ -116,3 +116,3 @@ | ||
'); | ||
assertEqual('sibling', doc.child(2).name()); | ||
assert.equal('sibling', doc.child(2).name()); | ||
}); | ||
@@ -126,4 +126,4 @@ | ||
'); | ||
assertEqual(doc, doc.root().parent()); | ||
assertEqual('child', doc.child().child().parent().name()); | ||
assert.equal(doc, doc.root().parent()); | ||
assert.equal('child', doc.child().child().parent().name()); | ||
}); | ||
@@ -138,5 +138,5 @@ | ||
var i; | ||
assertEqual(3, doc.childNodes().length); | ||
assert.equal(3, doc.childNodes().length); | ||
for (i = 0; i < children.length; i++) | ||
assertEqual(children[i], doc.child(i+1).name()); | ||
assert.equal(children[i], doc.child(i+1).name()); | ||
}); | ||
@@ -152,7 +152,7 @@ | ||
var child = doc.child(2); | ||
assertEqual('child', child.name()); | ||
assertEqual(children[0], child.prevSibling().name()); | ||
assertEqual(children[2], child.nextSibling().name()); | ||
assertEqual(null, child.prevSibling().prevSibling()); | ||
assertEqual(null, child.nextSibling().nextSibling()); | ||
assert.equal('child', child.name()); | ||
assert.equal(children[0], child.prevSibling().name()); | ||
assert.equal(children[2], child.nextSibling().name()); | ||
assert.equal(null, child.prevSibling().prevSibling()); | ||
assert.equal(null, child.nextSibling().nextSibling()); | ||
}); | ||
@@ -172,7 +172,7 @@ | ||
var child = doc.child(4); | ||
assertEqual('child', child.name()); | ||
assertEqual(children[0], child.prevElement().name()); | ||
assertEqual(children[2], child.nextElement().name()); | ||
assertEqual(null, child.prevElement().prevElement()); | ||
assertEqual(null, child.nextElement().nextElement()); | ||
assert.equal('child', child.name()); | ||
assert.equal(children[0], child.prevElement().name()); | ||
assert.equal(children[2], child.nextElement().name()); | ||
assert.equal(null, child.prevElement().prevElement()); | ||
assert.equal(null, child.nextElement().nextElement()); | ||
}); | ||
@@ -179,0 +179,0 @@ }); |
@@ -26,3 +26,3 @@ with(require('./helpers')) { | ||
it('has a '+accessor+' accessor', function() { | ||
assertEqual('object', typeof synErr[accessor]); | ||
assert.equal('object', typeof synErr[accessor]); | ||
}); | ||
@@ -29,0 +29,0 @@ } |
@@ -10,11 +10,11 @@ with(require('./helpers')) { | ||
var doc = libxml.parseXmlString(str); | ||
assertEqual('1.0', doc.version()); | ||
assertEqual('UTF-8', doc.encoding()); | ||
assertEqual('root', doc.root().name()); | ||
assertEqual('child', doc.get('child').name()); | ||
assertEqual('grandchild', doc.get('child').get('grandchild').name()); | ||
assertEqual('with love', doc.get('child/grandchild').text()); | ||
assertEqual('sibling', doc.get('sibling').name()); | ||
assertEqual('with content!', doc.get('sibling').text()); | ||
assertEqual(str, doc.toString()); | ||
assert.equal('1.0', doc.version()); | ||
assert.equal('UTF-8', doc.encoding()); | ||
assert.equal('root', doc.root().name()); | ||
assert.equal('child', doc.get('child').name()); | ||
assert.equal('grandchild', doc.get('child').get('grandchild').name()); | ||
assert.equal('with love', doc.get('child/grandchild').text()); | ||
assert.equal('sibling', doc.get('sibling').name()); | ||
assert.equal('with content!', doc.get('sibling').text()); | ||
assert.equal(str, doc.toString()); | ||
}); | ||
@@ -24,10 +24,10 @@ | ||
var doc = libxml.parseXmlFile(filename); | ||
assertEqual('1.0', doc.version()); | ||
assertEqual('UTF-8', doc.encoding()); | ||
assertEqual('root', doc.root().name()); | ||
assertEqual('child', doc.get('child').name()); | ||
assertEqual('grandchild', doc.get('child').get('grandchild').name()); | ||
assertEqual('with love', doc.get('child/grandchild').text()); | ||
assertEqual('sibling', doc.get('sibling').name()); | ||
assertEqual('with content!', doc.get('sibling').text()); | ||
assert.equal('1.0', doc.version()); | ||
assert.equal('UTF-8', doc.encoding()); | ||
assert.equal('root', doc.root().name()); | ||
assert.equal('child', doc.get('child').name()); | ||
assert.equal('grandchild', doc.get('child').get('grandchild').name()); | ||
assert.equal('with love', doc.get('child/grandchild').text()); | ||
assert.equal('sibling', doc.get('sibling').name()); | ||
assert.equal('with content!', doc.get('sibling').text()); | ||
}); | ||
@@ -58,3 +58,3 @@ }); | ||
}; | ||
assertEqual(errorControl, err); | ||
assert.deepEqual(errorControl, err); | ||
}); | ||
@@ -81,4 +81,4 @@ }); | ||
}; | ||
assertEqual(1, doc.errors().length); | ||
assertEqual(err.code, doc.errors()[0].code); | ||
assert.equal(1, doc.errors().length); | ||
assert.equal(err.code, doc.errors()[0].code); | ||
}); | ||
@@ -110,3 +110,3 @@ }); | ||
}; | ||
assertEqual(errorControl.code, err.code); | ||
assert.equal(errorControl.code, err.code); | ||
}); | ||
@@ -134,4 +134,4 @@ }); | ||
}; | ||
assertEqual(1, doc.errors().length); | ||
assertEqual(err.code, doc.errors()[0].code); | ||
assert.equal(1, doc.errors().length); | ||
assert.equal(err.code, doc.errors()[0].code); | ||
}); | ||
@@ -138,0 +138,0 @@ }); |
@@ -8,3 +8,3 @@ with(require('./helpers')) { | ||
function createParser(parserType) { | ||
parser = new libxml[parserType](function(cb) { | ||
var parser = new libxml[parserType](function(cb) { | ||
function argsToArray(args) { | ||
@@ -16,3 +16,3 @@ var ary = []; | ||
return ary; | ||
}; | ||
} | ||
@@ -58,3 +58,3 @@ cb.onStartDocument(function() { | ||
return parser; | ||
}; | ||
} | ||
@@ -71,3 +71,3 @@ beforeEach(function() { | ||
var test = JSON.stringify(callbacks); | ||
assertEqual(control, test); | ||
assert.equal(control, test); | ||
}); | ||
@@ -84,3 +84,3 @@ | ||
control.error = [["Extra content at the end of the document\n"]]; | ||
assertEqual(JSON.stringify(control), JSON.stringify(callbacks)); | ||
assert.equal(JSON.stringify(control), JSON.stringify(callbacks)); | ||
}); | ||
@@ -93,3 +93,3 @@ | ||
var control = clone(callbackControl); | ||
assertEqual(JSON.stringify(control), JSON.stringify(callbacks)); | ||
assert.deepEqual(control, callbacks); | ||
}); | ||
@@ -101,6 +101,8 @@ | ||
for (var i=0; i<10; i++) | ||
parser.parseString(str); | ||
for (var i=0; i<10; i++) { | ||
gc(); | ||
parser.parseString(str); | ||
} | ||
assert(true); | ||
assert.ok(true); | ||
}); | ||
@@ -111,6 +113,8 @@ | ||
for (var i=0; i<10; i++) | ||
parser.parseFile(filename); | ||
for (var i=0; i<10; i++) { | ||
gc(); | ||
parser.parseFile(filename); | ||
} | ||
assert(true); | ||
assert.ok(true); | ||
}); | ||
@@ -117,0 +121,0 @@ }); |
@@ -31,3 +31,4 @@ /* | ||
* // place code and assertions here | ||
* // available: assert(x), assertEqual(x, y), assertNotEqual(x, y) | ||
* // assert module is available | ||
assert.ok(true); | ||
* }); | ||
@@ -39,3 +40,3 @@ * | ||
* promise.addCallback(function(){ | ||
* assert(false); | ||
* assert.ok(false); | ||
* }) | ||
@@ -53,2 +54,6 @@ * setTimeout(function(){ promise.emitSuccess() }, 500); | ||
with(require('sys')) { | ||
if (typeof gc == 'undefined') var gc = function() {} | ||
if (process.argv) { process.ARGV = process.argv; } | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
@@ -59,4 +64,4 @@ var fs = require('fs'); | ||
var specFailures = []; | ||
var specVerbose = process.ARGV.join(";").match(/;=verbose/); | ||
var specVerbose = process.ARGV.join(";").match(/;(--verbose|-v)/); | ||
var describe = function(name, func) { | ||
@@ -69,2 +74,3 @@ specStack.push(name); | ||
specStack.pop(); | ||
gc(); | ||
}; | ||
@@ -90,2 +96,3 @@ | ||
specAfterEach(); | ||
gc(); | ||
}; | ||
@@ -174,16 +181,2 @@ | ||
var assert = function(value) { | ||
value ? specPass() : specFail("Expected " + value + " to be true"); | ||
}; | ||
var assertEqual = function(a, b) { | ||
var debugA = inspect(a), debugB = inspect(b); | ||
debugA == debugB ? specPass() : specFail("Expected:\n" + debugA + "\n\n" + "Found:\n" + debugB); | ||
}; | ||
var assertNotEqual = function(a, b) { | ||
var debugA = inspect(a), debugB = inspect(b); | ||
debugA != debugB ? specPass() : specFail("Expected:\n" + debugA + "\n\nto not equal:\n" + debugB); | ||
}; | ||
var beforeEach = function(func) { | ||
@@ -190,0 +183,0 @@ specBeforeEach = func; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
196723
73
1578
0
68
1
3