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