-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pseudos: implement :icontains, case-insensitive version of :contains
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
var CSSselect = require("../"), | ||
makeDom = require("htmlparser2").parseDOM, | ||
assert = require("assert"); | ||
|
||
var dom = makeDom("<div><p>In the end, it doesn't really Matter.</p><div>Indeed-that's a delicate matter.</div>"); | ||
|
||
describe("icontains", function(){ | ||
describe("ignore case", function(){ | ||
it("should match full string", function(){ | ||
var matches = CSSselect.selectAll(":icontains(indeed-that's a delicate matter.)", dom); | ||
assert.equal(matches.length, 2); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[1]]); | ||
matches = CSSselect.selectAll(":icontains(inDeeD-THAT's a DELICATE matteR.)", dom); | ||
assert.equal(matches.length, 2); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[1]]); | ||
}); | ||
|
||
it("should match substring", function(){ | ||
var matches = CSSselect.selectAll(":icontains(indeed)", dom); | ||
assert.equal(matches.length, 2); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[1]]); | ||
matches = CSSselect.selectAll(":icontains(inDeeD)", dom); | ||
assert.equal(matches.length, 2); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[1]]); | ||
}); | ||
|
||
it("should match specific element", function(){ | ||
var matches = CSSselect.selectAll("p:icontains(matter)", dom); | ||
assert.equal(matches.length, 1); | ||
assert.deepEqual(matches, [dom[0].children[0]]); | ||
matches = CSSselect.selectAll("p:icontains(mATter)", dom); | ||
assert.equal(matches.length, 1); | ||
assert.deepEqual(matches, [dom[0].children[0]]); | ||
}); | ||
|
||
it("should match multiple elements", function(){ | ||
var matches = CSSselect.selectAll(":icontains(matter)", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
matches = CSSselect.selectAll(":icontains(mATter)", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
}); | ||
|
||
it("should match empty string", function(){ | ||
var matches = CSSselect.selectAll(":icontains()", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
}); | ||
|
||
it("should match quoted string", function(){ | ||
var matches = CSSselect.selectAll(":icontains('')", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
matches = CSSselect.selectAll("p:icontains('matter')", dom); | ||
assert.equal(matches.length, 1); | ||
assert.deepEqual(matches, [dom[0].children[0]]); | ||
matches = CSSselect.selectAll("p:icontains(\"matter\")", dom); | ||
assert.equal(matches.length, 1); | ||
assert.deepEqual(matches, [dom[0].children[0]]); | ||
}); | ||
|
||
it("should match whitespace", function(){ | ||
var matches = CSSselect.selectAll(":icontains( matter)", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
matches = CSSselect.selectAll(":icontains( mATter)", dom); | ||
assert.equal(matches.length, 3); | ||
assert.deepEqual(matches, [dom[0], dom[0].children[0], | ||
dom[0].children[1]]); | ||
}); | ||
}); | ||
|
||
describe("no matches", function(){ | ||
it("should not match", function(){ | ||
var matches = CSSselect.selectAll("p:icontains(indeed)", dom); | ||
assert.equal(matches.length, 0); | ||
}); | ||
|
||
}); | ||
}); |