Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/common.js

Issue 30013613: Noissue - Add more tests for qualifySelector() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 21, 2019, 8:21 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/common.js
===================================================================
--- a/test/common.js
+++ b/test/common.js
@@ -28,14 +28,170 @@
{qualifySelector} = sandboxedRequire("../lib/common")
);
callback();
};
exports.testQualifySelector = function(test)
{
+ // Simple selectors.
+ test.equal(qualifySelector("#foo", "div"), "div#foo");
+ test.equal(qualifySelector(".foo", "div"), "div.foo");
+ test.equal(qualifySelector("div", "#foo"), "div#foo");
+ test.equal(qualifySelector("div", ".foo"), "div.foo");
+ test.equal(qualifySelector("div#bar", ".foo"), "div.foo#bar");
test.equal(qualifySelector("div.bar", "#foo"), "div#foo.bar");
+
+ // Compound selectors.
test.equal(qualifySelector("body #foo", "div"), "body div#foo");
- test.equal(qualifySelector(".3bcRuc4 *", "div"), ".3bcRuc4 div");
+ test.equal(qualifySelector("body .foo", "div"), "body div.foo");
+ test.equal(qualifySelector("body div", "#foo"), "body div#foo");
+ test.equal(qualifySelector("body div", ".foo"), "body div.foo");
+ test.equal(qualifySelector("body div#bar", ".foo"), "body div.foo#bar");
+ test.equal(qualifySelector("body div.bar", "#foo"), "body div#foo.bar");
+
+ // Compound selectors with universal selector.
+ test.equal(qualifySelector("#foo *", "div"), "#foo div");
+ test.equal(qualifySelector(".foo *", "div"), ".foo div");
+ test.equal(qualifySelector("div *", "#foo"), "div #foo");
+ test.equal(qualifySelector("div *", ".foo"), "div .foo");
+ test.equal(qualifySelector("div#bar *", ".foo"), "div#bar .foo");
+ test.equal(qualifySelector("div.bar *", "#foo"), "div.bar #foo");
+
+ // Compound selectors with pseudo-class with parentheses.
+ test.equal(qualifySelector("body #foo:nth-child(1)", "div"),
+ "body div#foo:nth-child(1)");
+ test.equal(qualifySelector("body .foo:nth-child(1)", "div"),
+ "body div.foo:nth-child(1)");
+ test.equal(qualifySelector("body div:nth-child(1)", "#foo"),
+ "body div#foo:nth-child(1)");
+ test.equal(qualifySelector("body div:nth-child(1)", ".foo"),
+ "body div.foo:nth-child(1)");
+ test.equal(qualifySelector("body div#bar:nth-child(1)", ".foo"),
+ "body div.foo#bar:nth-child(1)");
+ test.equal(qualifySelector("body div.bar:nth-child(1)", "#foo"),
+ "body div#foo.bar:nth-child(1)");
+
+ // Compound selectors with pseudo-class with parentheses containing extra
+ // whitespace.
+ test.equal(qualifySelector("body #foo:nth-child( 1 )", "div"),
+ "body div#foo:nth-child( 1 )");
+ test.equal(qualifySelector("body .foo:nth-child( 1 )", "div"),
+ "body div.foo:nth-child( 1 )");
+ test.equal(qualifySelector("body div:nth-child( 1 )", "#foo"),
+ "body div#foo:nth-child( 1 )");
+ test.equal(qualifySelector("body div:nth-child( 1 )", ".foo"),
+ "body div.foo:nth-child( 1 )");
+ test.equal(qualifySelector("body div#bar:nth-child( 1 )", ".foo"),
+ "body div.foo#bar:nth-child( 1 )");
+ test.equal(qualifySelector("body div.bar:nth-child( 1 )", "#foo"),
+ "body div#foo.bar:nth-child( 1 )");
+
+ // Compound selectors with child combinator and pseudo-class with
+ // parentheses.
+ test.equal(qualifySelector("body > #foo:nth-child(1)", "div"),
+ "body > div#foo:nth-child(1)");
+ test.equal(qualifySelector("body > .foo:nth-child(1)", "div"),
+ "body > div.foo:nth-child(1)");
+ test.equal(qualifySelector("body > div:nth-child(1)", "#foo"),
+ "body > div#foo:nth-child(1)");
+ test.equal(qualifySelector("body > div:nth-child(1)", ".foo"),
+ "body > div.foo:nth-child(1)");
+ test.equal(qualifySelector("body > div#bar:nth-child(1)", ".foo"),
+ "body > div.foo#bar:nth-child(1)");
+ test.equal(qualifySelector("body > div.bar:nth-child(1)", "#foo"),
+ "body > div#foo.bar:nth-child(1)");
+
+ // Compound selectors with child combinator surrounded by no whitespace and
+ // pseudo-class with parentheses.
+ test.equal(qualifySelector("body>#foo:nth-child(1)", "div"),
+ "body>div#foo:nth-child(1)");
+ test.equal(qualifySelector("body>.foo:nth-child(1)", "div"),
+ "body>div.foo:nth-child(1)");
+ test.equal(qualifySelector("body>div:nth-child(1)", "#foo"),
+ "body>div#foo:nth-child(1)");
+ test.equal(qualifySelector("body>div:nth-child(1)", ".foo"),
+ "body>div.foo:nth-child(1)");
+ test.equal(qualifySelector("body>div#bar:nth-child(1)", ".foo"),
+ "body>div.foo#bar:nth-child(1)");
+ test.equal(qualifySelector("body>div.bar:nth-child(1)", "#foo"),
+ "body>div#foo.bar:nth-child(1)");
+
+ // Compound selectors with adjacent sibling combinator and pseudo-class with
+ // parentheses.
+ test.equal(qualifySelector("article + #foo:nth-child(1)", "div"),
+ "article + div#foo:nth-child(1)");
+ test.equal(qualifySelector("article + .foo:nth-child(1)", "div"),
+ "article + div.foo:nth-child(1)");
+ test.equal(qualifySelector("article + div:nth-child(1)", "#foo"),
+ "article + div#foo:nth-child(1)");
+ test.equal(qualifySelector("article + div:nth-child(1)", ".foo"),
+ "article + div.foo:nth-child(1)");
+ test.equal(qualifySelector("article + div#bar:nth-child(1)", ".foo"),
+ "article + div.foo#bar:nth-child(1)");
+ test.equal(qualifySelector("article + div.bar:nth-child(1)", "#foo"),
+ "article + div#foo.bar:nth-child(1)");
+
+ // Compound selectors with general sibling combinator and pseudo-class with
+ // parentheses.
+ test.equal(qualifySelector("article ~ #foo:nth-child(1)", "div"),
+ "article ~ div#foo:nth-child(1)");
+ test.equal(qualifySelector("article ~ .foo:nth-child(1)", "div"),
+ "article ~ div.foo:nth-child(1)");
+ test.equal(qualifySelector("article ~ div:nth-child(1)", "#foo"),
+ "article ~ div#foo:nth-child(1)");
+ test.equal(qualifySelector("article ~ div:nth-child(1)", ".foo"),
+ "article ~ div.foo:nth-child(1)");
+ test.equal(qualifySelector("article ~ div#bar:nth-child(1)", ".foo"),
+ "article ~ div.foo#bar:nth-child(1)");
+ test.equal(qualifySelector("article ~ div.bar:nth-child(1)", "#foo"),
+ "article ~ div#foo.bar:nth-child(1)");
+
+ // Compound selectors with child combinator and pseudo-element.
+ test.equal(qualifySelector("body > #foo::first-child", "div"),
+ "body > div#foo::first-child");
+ test.equal(qualifySelector("body > .foo::first-child", "div"),
+ "body > div.foo::first-child");
+ test.equal(qualifySelector("body > div::first-child", "#foo"),
+ "body > div#foo::first-child");
+ test.equal(qualifySelector("body > div::first-child", ".foo"),
+ "body > div.foo::first-child");
+ test.equal(qualifySelector("body > div#bar::first-child", ".foo"),
+ "body > div.foo#bar::first-child");
+ test.equal(qualifySelector("body > div.bar::first-child", "#foo"),
+ "body > div#foo.bar::first-child");
+
+ // Compound selectors with attribute selector.
+ test.equal(qualifySelector("body #foo[style='display: block']", "div"),
+ "body div#foo[style='display: block']");
+ test.equal(qualifySelector("body .foo[style='display: block']", "div"),
+ "body div.foo[style='display: block']");
+ test.equal(qualifySelector("body div[style='display: block']", "#foo"),
+ "body div#foo[style='display: block']");
+ test.equal(qualifySelector("body div[style='display: block']", ".foo"),
+ "body div.foo[style='display: block']");
+ test.equal(qualifySelector("body div#bar[style='display: block']", ".foo"),
+ "body div.foo#bar[style='display: block']");
+ test.equal(qualifySelector("body div.bar[style='display: block']", "#foo"),
+ "body div#foo.bar[style='display: block']");
+
+ // Compound selectors with unqualified attribute selector.
+ test.equal(qualifySelector("body [style='display: block']", "div"),
+ "body div[style='display: block']");
+ test.equal(qualifySelector("body [style='display: block']", "#foo"),
+ "body #foo[style='display: block']");
+ test.equal(qualifySelector("body [style='display: block']", ".foo"),
+ "body .foo[style='display: block']");
+
+ // Multiple selectors.
+ test.equal(qualifySelector("#foo, #bar", "div"), "div#foo, div#bar");
+ test.equal(qualifySelector(".foo, .bar", "div"), "div.foo, div.bar");
+ test.equal(qualifySelector("div, .bar", "#foo"), "div#foo, #foo.bar");
+ test.equal(qualifySelector("div, #bar", ".foo"), "div.foo, .foo#bar");
+
+ // Compound selector with class selector containing Unicode composite
+ // character.
+ test.equal(qualifySelector("body .\ud83d\ude42", "img"),
+ "body img.\ud83d\ude42");
test.done();
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld