Skip to content
Browse files

Continue porting tests

  • Loading branch information...
1 parent a57aa9e commit 77827fca5ad9e01d9336f171e69fe6288a907f6d Harry Fuecks committed
Showing with 54 additions and 2 deletions.
  1. +2 −2 lib/soupselect.js
  2. +52 −0 tests/soupselect.js
View
4 lib/soupselect.js
@@ -100,9 +100,9 @@ exports.select = function(dom, selector) {
var found = [];
currentContext.forEach(function(context) {
if ( tag ) {
- context = htmlparser.DomUtils.getElementsByTagName(tag, context)
+ context = domUtils.getElementsByTagName(tag, context)
}
- found = found.concat(htmlparser.DomUtils.getElements(options, context));
+ found = found.concat(domUtils.getElements(options, context));
});
currentContext = found
View
52 tests/soupselect.js
@@ -32,6 +32,12 @@ function assertSelects(test, dom, selector, expected_ids) {
);
}
+function assertSelectMultiple(test, dom, specs) {
+ specs.forEach(function(spec){
+ assertSelects(test, dom, spec[0], spec[1]);
+ });
+}
+
exports.basicSelectors = {
one_tag_one: function(test) {
runTest(test, function(dom) {
@@ -64,5 +70,51 @@ exports.basicSelectors = {
assertSelects(test, dom, selector, ['main', 'inner', 'footer']);
});
});
+ },
+
+ tag_no_match: function(test) {
+ runTest(test, function(dom) {
+ test.equal(select(dom, 'del').length, 0);
+ });
+ },
+
+ tag_invalid_tag: function(test) {
+ runTest(test, function(dom) {
+ test.equal(select(dom, 'tag%t').length, 0);
+ });
+ },
+
+ header_tags: function(test) {
+ runTest(test, function(dom) {
+ assertSelectMultiple(test, dom, [
+ ['h1', ['header1']],
+ ['h2', ['header2', 'header3']]
+ ]);
+ });
+ },
+
+ // class_one: function(test) {
+ // runTest(test, function(dom) {
+ // ['.onep', 'p.onep', 'html p.onep'].forEach(function(selector) {
+ // var els = select(dom, selector);
+ // test.equal(els.length, 1);
+ // test.equal(els[0].name, 'p');
+ // test.equal(els[0].attribs.class, 'onep');
+ // });
+ // });
+ // },
+
+ class_mismatched_tag: function(test) {
+ runTest(test, function(dom) {
+ test.equal(select(dom, 'div.onep').length, 0);
+ })
+ },
+
+ one_id: function(test) {
+ runTest(test, function(dom) {
+ ['div#inner', '#inner', 'div div#inner'].forEach(function(selector) {
+ assertSelects(test, dom, selector, ['inner']);
+ });
+ });
}
}

0 comments on commit 77827fc

Please sign in to comment.
Something went wrong with that request. Please try again.