monolith/src/tests/url/url_has_protocol.rs

92 lines
3.2 KiB
Rust
Raw Normal View History

2020-03-23 03:08:41 +01:00
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
#[cfg(test)]
mod passing {
use crate::url;
2020-03-23 03:08:41 +01:00
#[test]
fn mailto() {
assert!(url::url_has_protocol(
"mailto:somebody@somewhere.com?subject=hello"
));
}
2020-03-23 03:08:41 +01:00
#[test]
fn tel() {
assert!(url::url_has_protocol("tel:5551234567"));
}
2020-03-23 03:08:41 +01:00
#[test]
fn ftp_no_slashes() {
assert!(url::url_has_protocol("ftp:some-ftp-server.com"));
}
2020-03-23 03:08:41 +01:00
#[test]
fn ftp_with_credentials() {
assert!(url::url_has_protocol(
"ftp://user:password@some-ftp-server.com"
));
}
2020-03-23 03:08:41 +01:00
#[test]
fn javascript() {
assert!(url::url_has_protocol("javascript:void(0)"));
}
2020-03-23 03:08:41 +01:00
#[test]
fn http() {
assert!(url::url_has_protocol("http://news.ycombinator.com"));
}
#[test]
fn https() {
assert!(url::url_has_protocol("https://github.com"));
}
2020-03-23 03:08:41 +01:00
#[test]
fn mailto_uppercase() {
assert!(url::url_has_protocol(
"MAILTO:somebody@somewhere.com?subject=hello"
));
}
2020-03-23 03:08:41 +01:00
}
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
// █████╗ ███████║██║██║ ██║██╔██╗ ██║██║ ███╗
// ██╔══╝ ██╔══██║██║██║ ██║██║╚██╗██║██║ ██║
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
#[cfg(test)]
mod failing {
use crate::utils;
2020-03-23 03:08:41 +01:00
#[test]
fn url_with_no_protocol() {
assert!(!url::url_has_protocol(
"//some-hostname.com/some-file.html"
));
}
2020-03-23 03:08:41 +01:00
#[test]
fn relative_path() {
assert!(!url::url_has_protocol("some-hostname.com/some-file.html"));
}
#[test]
fn relative_to_root_path() {
assert!(!url::url_has_protocol("/some-file.html"));
}
2020-03-23 03:08:41 +01:00
#[test]
fn empty_string() {
assert!(!url::url_has_protocol(""));
}
2020-03-23 03:08:41 +01:00
}