xpath
Advanced tools
Comparing version 0.0.26 to 0.0.27
{ | ||
"name": "xpath", | ||
"version": "0.0.26", | ||
"version": "0.0.27", | ||
"description": "DOM 3 XPath implemention and helper for node.js.", | ||
@@ -9,3 +9,3 @@ "engines": { | ||
"author": { | ||
"name": "Cameron McCormac" | ||
"name": "Cameron McCormack" | ||
}, | ||
@@ -38,3 +38,3 @@ "contributors": [ | ||
], | ||
"license": "CC-BY-SA-2.0" | ||
"license": "MIT" | ||
} |
@@ -131,1 +131,4 @@ ## xpath | ||
[MDN]: https://developer.mozilla.org/en/docs/Web/API/Document/evaluate | ||
## License | ||
MIT |
68
test.js
@@ -5,2 +5,4 @@ var xpath = require('./xpath.js') | ||
var xhtmlNs = 'http://www.w3.org/1999/xhtml'; | ||
module.exports = { | ||
@@ -999,11 +1001,12 @@ 'api': function(test) { | ||
,'should allow null namespaces for null prefixes': function (test) { | ||
var doc = new dom().parseFromString('<html><head></head><body><p>Hi Ron!</p><my:p xmlns:my="http://www.example.com/my">Hi Draco!</p><p>Hi Hermione!</p></body></html>', 'text/html'); | ||
var markup = '<html><head></head><body><p>Hi Ron!</p><my:p xmlns:my="http://www.example.com/my">Hi Draco!</p><p>Hi Hermione!</p></body></html>'; | ||
var docHtml = new dom().parseFromString(markup, 'text/html'); | ||
var noPrefixPath = xpath.parse('/html/body/p[2]'); | ||
var greetings1 = noPrefixPath.select({ node: doc }); | ||
var greetings1 = noPrefixPath.select({ node: docHtml, allowAnyNamespaceForNoPrefix: false }); | ||
assert.equal(0, greetings1.length); | ||
var allowAnyNamespaceOptions = { node: doc, allowAnyNamespaceForNoPrefix: true }; | ||
var allowAnyNamespaceOptions = { node: docHtml, allowAnyNamespaceForNoPrefix: true }; | ||
@@ -1020,6 +1023,6 @@ // if allowAnyNamespaceForNoPrefix specified, allow using prefix-less node tests to match nodes with no prefix | ||
var nsm = { html: 'http://www.w3.org/1999/xhtml', other: 'http://www.example.com/other' }; | ||
var nsm = { html: xhtmlNs, other: 'http://www.example.com/other' }; | ||
var prefixPath = xpath.parse('/html:html/body/html:p'); | ||
var optionsWithNamespaces = { node: doc, allowAnyNamespaceForNoPrefix: true, namespaces: nsm }; | ||
var optionsWithNamespaces = { node: docHtml, allowAnyNamespaceForNoPrefix: true, namespaces: nsm }; | ||
@@ -1037,2 +1040,57 @@ // if the path uses prefixes, they have to match | ||
} | ||
,'support isHtml option' : function (test){ | ||
var markup = '<html><head></head><body><p>Hi Ron!</p><my:p xmlns:my="http://www.example.com/my">Hi Draco!</p><p>Hi Hermione!</p></body></html>'; | ||
var docHtml = new dom().parseFromString(markup, 'text/html'); | ||
var ns = { h: xhtmlNs }; | ||
// allow matching on unprefixed nodes | ||
var greetings1 = xpath.parse('/html/body/p').select({ node: docHtml, isHtml: true }); | ||
assert.equal(2, greetings1.length); | ||
// allow case insensitive match | ||
var greetings2 = xpath.parse('/h:html/h:bOdY/h:p').select({ node: docHtml, namespaces: ns, isHtml: true }); | ||
assert.equal(2, greetings2.length); | ||
// non-html mode: allow select if case and namespaces match | ||
var greetings3 = xpath.parse('/h:html/h:body/h:p').select({ node: docHtml, namespaces: ns }); | ||
assert.equal(2, greetings3.length); | ||
// non-html mode: require namespaces | ||
var greetings4 = xpath.parse('/html/body/p').select({ node: docHtml, namespaces: ns }); | ||
assert.equal(0, greetings4.length); | ||
// non-html mode: require case to match | ||
var greetings5 = xpath.parse('/h:html/h:bOdY/h:p').select({ node: docHtml, namespaces: ns }); | ||
assert.equal(0, greetings5.length); | ||
test.done(); | ||
} | ||
,"builtin functions": function (test) { | ||
var translated = xpath.parse('translate("hello", "lhho", "yHb")').evaluateString(); | ||
assert.equal('Heyy', translated); | ||
var characters = new dom().parseFromString('<characters><character>Harry</character><character>Ron</character><character>Hermione</character></characters>'); | ||
var firstTwo = xpath.parse('/characters/character[position() <= 2]').select({ node: characters }); | ||
assert.equal(2, firstTwo.length); | ||
assert.equal('Harry', firstTwo[0].textContent); | ||
assert.equal('Ron', firstTwo[1].textContent); | ||
var last = xpath.parse('/characters/character[last()]').select({ node: characters }); | ||
assert.equal(1, last.length); | ||
assert.equal('Hermione', last[0].textContent); | ||
test.done(); | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Copyleft License
License(Experimental) Copyleft license information was found
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found
Found 1 instance in 1 package
195832
0
100
4993
133