update tests for new domain matching algorithm

pull/270/head
Sunshine 2 years ago
parent 145550e637
commit 9356161a89
No known key found for this signature in database
GPG Key ID: B80CA68703CD8AB1

@ -10,9 +10,25 @@ mod passing {
use monolith::utils; use monolith::utils;
#[test] #[test]
fn sub_domain_is_within_domain() { fn sub_domain_is_within_dotted_sub_domain() {
assert!(utils::domain_is_within_domain( assert!(utils::domain_is_within_domain(
"news.ycombinator.com", "news.ycombinator.com",
".news.ycombinator.com"
));
}
#[test]
fn domain_is_within_dotted_domain() {
assert!(utils::domain_is_within_domain(
"ycombinator.com",
".ycombinator.com"
));
}
#[test]
fn dotted_domain_is_within_domain() {
assert!(utils::domain_is_within_domain(
".ycombinator.com",
"ycombinator.com" "ycombinator.com"
)); ));
} }
@ -26,8 +42,11 @@ mod passing {
} }
#[test] #[test]
fn domain_is_within_top_level_domain() { fn sub_domain_is_within_dotted_top_level_domain() {
assert!(utils::domain_is_within_domain("ycombinator.com", "com")); assert!(utils::domain_is_within_domain(
"news.ycombinator.com",
".com"
));
} }
#[test] #[test]
@ -39,12 +58,46 @@ mod passing {
} }
#[test] #[test]
fn sub_domain_is_within_dotted_itself() { fn domain_with_trailing_dot_is_within_itself() {
assert!(utils::domain_is_within_domain(
"ycombinator.com.",
"ycombinator.com"
));
}
#[test]
fn domain_with_trailing_dot_is_within_single_dot() {
assert!(utils::domain_is_within_domain(
"ycombinator.com.",
"."
));
}
#[test]
fn domain_matches_single_dot() {
assert!(utils::domain_is_within_domain( assert!(utils::domain_is_within_domain(
"ycombinator.com", "ycombinator.com",
"."
));
}
#[test]
fn dotted_domain_must_be_within_dotted_domain() {
assert!(utils::domain_is_within_domain(
".ycombinator.com",
".ycombinator.com" ".ycombinator.com"
)); ));
} }
#[test]
fn empty_is_within_dot() {
assert!(utils::domain_is_within_domain("", "."));
}
#[test]
fn both_dots() {
assert!(utils::domain_is_within_domain(".", "."));
}
} }
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗ // ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
@ -59,7 +112,20 @@ mod failing {
use monolith::utils; use monolith::utils;
#[test] #[test]
fn sub_domain_is_not_within_domain() { fn sub_domain_must_not_be_within_domain() {
assert!(!utils::domain_is_within_domain(
"news.ycombinator.com",
"ycombinator.com"
));
}
#[test]
fn domain_must_not_be_within_top_level_domain() {
assert!(!utils::domain_is_within_domain("ycombinator.com", "com"));
}
#[test]
fn different_domains_must_not_be_within_one_another() {
assert!(!utils::domain_is_within_domain( assert!(!utils::domain_is_within_domain(
"news.ycombinator.com", "news.ycombinator.com",
"kernel.org" "kernel.org"
@ -67,7 +133,7 @@ mod failing {
} }
#[test] #[test]
fn sub_domain_is_not_within_top_level_domain() { fn sub_domain_is_not_within_wrong_top_level_domain() {
assert!(!utils::domain_is_within_domain( assert!(!utils::domain_is_within_domain(
"news.ycombinator.com", "news.ycombinator.com",
"org" "org"
@ -75,12 +141,12 @@ mod failing {
} }
#[test] #[test]
fn no_domain_is_not_within_dot() { fn no_domain_can_be_within_empty_domain() {
assert!(!utils::domain_is_within_domain("news.ycombinator.com", ".")); assert!(!utils::domain_is_within_domain("ycombinator.com", ""));
} }
#[test] #[test]
fn no_domain_is_within_empty_domain() { fn both_can_not_be_empty() {
assert!(!utils::domain_is_within_domain("news.ycombinator.com", "")); assert!(!utils::domain_is_within_domain("", ""));
} }
} }

Loading…
Cancel
Save