From f7342120f0a7c2e4955fc4601794f31f46da8140 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Wed, 28 Feb 2024 16:55:26 +0100 Subject: [PATCH] drop tests that require unshipped support code --- src/blocker.rs | 172 ----------------------------------------- src/filters/network.rs | 28 ------- src/lib.rs | 4 - 3 files changed, 204 deletions(-) diff --git a/src/blocker.rs b/src/blocker.rs index 78d7edd..cc1435f 100644 --- a/src/blocker.rs +++ b/src/blocker.rs @@ -2135,175 +2135,3 @@ mod placeholder_string_tests { assert_eq!(block.filter, Some("NetworkFilter".to_string())); } } - -#[cfg(test)] -mod legacy_rule_parsing_tests { - use crate::test_utils::rules_from_lists; - use crate::lists::{parse_filters, FilterFormat, ParseOptions}; - use crate::blocker::{Blocker, BlockerOptions}; - use crate::blocker::vec_hashmap_len; - - struct ListCounts { - pub filters: usize, - pub cosmetic_filters: usize, - pub exceptions: usize, - pub duplicates: usize, - } - - impl std::ops::Add for ListCounts { - type Output = ListCounts; - - fn add(self, other: ListCounts) -> Self::Output { - ListCounts { - filters: self.filters + other.filters, - cosmetic_filters: self.cosmetic_filters + other.cosmetic_filters, - exceptions: self.exceptions + other.exceptions, - duplicates: 0, // Don't bother trying to calculate - lists could have cross-duplicated entries - } - } - } - - // number of expected EasyList cosmetic rules from old engine is 31144, but is incorrect as it skips a few particularly long rules that are nevertheless valid - // easyList = { 24478, 31144, 0, 5589 }; - // not handling (and not including) filters with the following options: - // - $popup - // - $elemhide - // difference from original counts caused by not handling document/subdocument options and possibly miscounting on the blocker side. - // Printing all non-cosmetic, non-html, non-comment/-empty rules and ones with no unsupported options yields 29142 items - // This engine also handles 3 rules that old one does not - const EASY_LIST: ListCounts = ListCounts { filters: 24064, cosmetic_filters: 31163, exceptions: 5796, duplicates: 0 }; - // easyPrivacy = { 11817, 0, 0, 1020 }; - // differences in counts explained by hashset size underreporting as detailed in the next two cases - const EASY_PRIVACY: ListCounts = ListCounts { filters: 11889, cosmetic_filters: 0, exceptions: 1021, duplicates: 2 }; - // ublockUnbreak = { 4, 8, 0, 94 }; - // differences in counts explained by client.hostAnchoredExceptionHashSet->GetSize() underreporting when compared to client.numHostAnchoredExceptionFilters - const UBLOCK_UNBREAK: ListCounts = ListCounts { filters: 4, cosmetic_filters: 8, exceptions: 98, duplicates: 0 }; - // braveUnbreak = { 31, 0, 0, 4 }; - // differences in counts explained by client.hostAnchoredHashSet->GetSize() underreporting when compared to client.numHostAnchoredFilters - const BRAVE_UNBREAK: ListCounts = ListCounts { filters: 32, cosmetic_filters: 0, exceptions: 4, duplicates: 0 }; - // disconnectSimpleMalware = { 2450, 0, 0, 0 }; - const DISCONNECT_SIMPLE_MALWARE: ListCounts = ListCounts { filters: 2450, cosmetic_filters: 0, exceptions: 0, duplicates: 0 }; - // spam404MainBlacklist = { 5629, 166, 0, 0 }; - const SPAM_404_MAIN_BLACKLIST: ListCounts = ListCounts { filters: 5629, cosmetic_filters: 166, exceptions: 0, duplicates: 0 }; - const MALWARE_DOMAIN_LIST: ListCounts = ListCounts { filters: 1104, cosmetic_filters: 0, exceptions: 0, duplicates: 3 }; - const MALWARE_DOMAINS: ListCounts = ListCounts { filters: 26853, cosmetic_filters: 0, exceptions: 0, duplicates: 48 }; - - fn check_list_counts(rule_lists: impl IntoIterator>, format: FilterFormat, expectation: ListCounts) { - let rules = rules_from_lists(rule_lists); - - let (network_filters, cosmetic_filters) = parse_filters(rules, true, ParseOptions { format, ..Default::default() }); - - assert_eq!( - (network_filters.len(), - network_filters.iter().filter(|f| f.is_exception()).count(), - cosmetic_filters.len()), - (expectation.filters + expectation.exceptions, - expectation.exceptions, - expectation.cosmetic_filters), - "Number of collected filters does not match expectation"); - - let blocker_options = BlockerOptions { - enable_optimizations: false, // optimizations will reduce number of rules - }; - - let blocker = Blocker::new(network_filters, &blocker_options); - - // Some filters in the filter_map are pointed at by multiple tokens, increasing the total number of items - assert!(vec_hashmap_len(&blocker.exceptions.filter_map) + vec_hashmap_len(&blocker.generic_hide.filter_map) - >= expectation.exceptions, "Number of collected exceptions does not match expectation"); - - assert!(vec_hashmap_len(&blocker.filters.filter_map) + - vec_hashmap_len(&blocker.importants.filter_map) + - vec_hashmap_len(&blocker.redirects.filter_map) + - vec_hashmap_len(&blocker.redirects.filter_map) + - vec_hashmap_len(&blocker.csp.filter_map) >= - expectation.filters - expectation.duplicates, "Number of collected network filters does not match expectation"); - } - - #[test] - fn parse_easylist() { - check_list_counts(["./data/test/easylist.txt"], FilterFormat::Standard, EASY_LIST); - } - - #[test] - fn parse_easyprivacy() { - check_list_counts(["./data/test/easyprivacy.txt"], FilterFormat::Standard, EASY_PRIVACY); - } - - #[test] - fn parse_ublock_unbreak() { - check_list_counts(["./data/test/ublock-unbreak.txt"], FilterFormat::Standard, UBLOCK_UNBREAK); - } - - #[test] - fn parse_brave_unbreak() { - check_list_counts(["./data/test/brave-unbreak.txt"], FilterFormat::Standard, BRAVE_UNBREAK); - } - - #[test] - fn parse_brave_disconnect_simple_malware() { - check_list_counts(["./data/test/disconnect-simple-malware.txt"], FilterFormat::Standard, DISCONNECT_SIMPLE_MALWARE); - } - - #[test] - fn parse_spam404_main_blacklist() { - check_list_counts(["./data/test/spam404-main-blacklist.txt"], FilterFormat::Standard, SPAM_404_MAIN_BLACKLIST); - } - - #[test] - fn parse_malware_domain_list() { - check_list_counts(["./data/test/malwaredomainlist.txt"], FilterFormat::Hosts, MALWARE_DOMAIN_LIST); - } - - #[test] - fn parse_malware_domain_list_just_hosts() { - check_list_counts(["./data/test/malwaredomainlist_justhosts.txt"], FilterFormat::Hosts, MALWARE_DOMAIN_LIST); - } - - #[test] - fn parse_malware_domains() { - check_list_counts(["./data/test/malwaredomains.txt"], FilterFormat::Hosts, MALWARE_DOMAINS); - } - - #[test] - fn parse_multilist() { - let expectation = EASY_LIST + EASY_PRIVACY + UBLOCK_UNBREAK + BRAVE_UNBREAK; - check_list_counts( - [ - "./data/test/easylist.txt", - "./data/test/easyprivacy.txt", - "./data/test/ublock-unbreak.txt", - "./data/test/brave-unbreak.txt", - ], - FilterFormat::Standard, - expectation, - ) - } - - #[test] - fn parse_malware_multilist() { - let expectation = SPAM_404_MAIN_BLACKLIST + DISCONNECT_SIMPLE_MALWARE; - check_list_counts( - [ - "./data/test/spam404-main-blacklist.txt", - "./data/test/disconnect-simple-malware.txt", - ], - FilterFormat::Standard, - expectation, - ) - } - - #[test] - fn parse_hosts_formats() { - let mut expectation = MALWARE_DOMAIN_LIST + MALWARE_DOMAINS; - expectation.duplicates = 69; - check_list_counts( - [ - "./data/test/malwaredomainlist.txt", - "./data/test/malwaredomains.txt", - ], - FilterFormat::Hosts, - expectation, - ) - } -} diff --git a/src/filters/network.rs b/src/filters/network.rs index 093b0e6..69f10d0 100644 --- a/src/filters/network.rs +++ b/src/filters/network.rs @@ -3386,31 +3386,3 @@ mod match_tests { assert_eq!(get_url_after_hostname("https://www.youtube.com/?aclksa=l&ai=DChcSEwioqMfq5", "google.com"), ""); } } - -#[cfg(test)] -mod hash_collision_tests { - use super::*; - - use crate::test_utils; - use crate::lists::parse_filters; - use std::collections::HashMap; - - #[test] - fn check_rule_ids_no_collisions() { - let rules = test_utils::rules_from_lists([ - "data/easylist.to/easylist/easylist.txt", - "data/easylist.to/easylist/easyprivacy.txt", - ]); - let (network_filters, _) = parse_filters(rules, true, Default::default()); - - let mut filter_ids: HashMap = HashMap::new(); - - for filter in network_filters { - let id = filter.get_id(); - let rule = *filter.raw_line.unwrap_or_default(); - let existing_rule = filter_ids.get(&id); - assert!(existing_rule.is_none() || existing_rule.unwrap() == &rule, "ID {} for {} already present from {}", id, rule, existing_rule.unwrap()); - filter_ids.insert(id, rule); - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 956f082..5db786a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,10 +37,6 @@ pub use engine::Engine; #[doc(inline)] pub use lists::FilterSet; -#[cfg(test)] -#[path = "../tests/test_utils.rs"] -mod test_utils; - #[cfg(test)] mod sync_tests { #[allow(unused)] -- 2.44.0