def test_rule_with_options(rule_text, results, use_re2): rule = AdblockRule(rule_text) rules = AdblockRules([rule_text], use_re2=use_re2) for url, params, match in results: assert rule.match_url(url, params) == match assert rules.should_block(url, params) == match
def test_documented_examples(rule_text, results, use_re2): rule = AdblockRule(rule_text) rules = AdblockRules([rule_text], use_re2=use_re2) for url in results["blocks"]: assert rule.match_url(url) assert rules.should_block(url) for url in results["doesn't block"]: assert not rule.match_url(url) assert not rules.should_block(url)
def test_is_comment(text): rule = AdblockRule(text) assert rule.is_comment assert not rule.is_html_rule assert not rule.is_exception assert rule.options == {} assert not rule.regex
def test_empty_rules(): rules = AdblockRules(["adv", "", " \t", AdblockRule("adv2")]) assert len(rules.rules) == 2
def test_rules_instantiation(): rule = AdblockRule("adv") rules = AdblockRules([rule]) assert rule.match_url("http://example.com/adv") assert rules.should_block("http://example.com/adv")
def test_is_html_rule(text): rule = AdblockRule(text) assert rule.is_html_rule assert not rule.is_comment
def test_options_extraction(text, result): rule = AdblockRule(text) assert rule.options == result
def test_domain_parsing(text, result): assert AdblockRule._parse_domain_option(text) == result
def test_option_splitting(text, result): assert AdblockRule._split_options(text) == result