xpath-to-css
Advanced tools
Comparing version
@@ -37,3 +37,3 @@ /** | ||
const subRegexes = { | ||
"tag": "([a-zA-Z][a-zA-Z0-9]{0,10}|\\*)", | ||
"tag": "([a-zA-Z][a-zA-Z0-9:-]{0,20}|\\*)", | ||
"attribute": "[.a-zA-Z_:][-\\w:.]*(\\(\\))?)", | ||
@@ -40,0 +40,0 @@ "value": "\\s*[\\w/:][-/\\w\\s,:;.]*" |
{ | ||
"name": "xpath-to-css", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"title": "XPath to CSS", | ||
@@ -20,4 +20,4 @@ "description": "Utility function for converting XPath expressions to CSS selectors", | ||
"devDependencies": { | ||
"tape": "^4.13.2" | ||
"tape": "^5.3.2" | ||
} | ||
} |
54
test.js
@@ -5,36 +5,44 @@ var test = require('tape'); | ||
test('input validation', function(assert) { | ||
assert.throws(xPathToCss, 'should throw an error if no xpath expression is provided'); | ||
assert.throws(xPathToCss.bind(null, '1'), 'should throw an error if an invalid xpath expression is provided'); | ||
assert.throws(xPathToCss, 'should throw an error if no xpath expression is provided'); | ||
assert.throws(xPathToCss.bind(null, '1'), 'should throw an error if an invalid xpath expression is provided'); | ||
assert.end(); | ||
assert.end(); | ||
}); | ||
test('conversion', function(assert) { | ||
var actual, expected; | ||
var actual, expected; | ||
actual = xPathToCss('/HTML/HEAD/TITLE'); | ||
expected = 'HTML > HEAD > TITLE'; | ||
assert.equal(actual, expected, 'should handle upper case'); | ||
actual = xPathToCss('/HTML/HEAD/TITLE'); | ||
expected = 'HTML > HEAD > TITLE'; | ||
assert.equal(actual, expected, 'should handle upper case'); | ||
actual = xPathToCss('/html/head/title'); | ||
expected = 'html > head > title'; | ||
assert.equal(actual, expected, 'should handle lower case'); | ||
actual = xPathToCss('/html/head/title'); | ||
expected = 'html > head > title'; | ||
assert.equal(actual, expected, 'should handle lower case'); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[5]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(5)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[5]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(5)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[10]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(10)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[10]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(10)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[123]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(123)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('/HTML/BODY/DIV[@id=\'menu\']/NAV/UL[123]'); | ||
expected = 'HTML > BODY > DIV#menu > NAV > UL:nth-of-type(123)'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('//div[@id="foo"][2]/span[@class="bar"]//a[contains(@class, "baz")]//img[1]'); | ||
expected = 'div#foo:nth-of-type(2) > span.bar a[class*="baz"] img:first-of-type'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('//div[@id="foo"][2]/span[@class="bar"]//a[contains(@class, "baz")]//img[1]'); | ||
expected = 'div#foo:nth-of-type(2) > span.bar a[class*="baz"] img:first-of-type'; | ||
assert.equal(actual, expected); | ||
assert.end(); | ||
actual = xPathToCss('//div/custom:element'); | ||
expected = 'div > custom:element'; | ||
assert.equal(actual, expected); | ||
actual = xPathToCss('//div/custom-element'); | ||
expected = 'div > custom-element'; | ||
assert.equal(actual, expected); | ||
assert.end(); | ||
}); |
11108
2.75%180
3.45%