[wip] unit tests
- strip unneeded mod `test_util::mock_ids::tests` - coverage for `sharry::uri`
This commit is contained in:
parent
037e59df4f
commit
1ac4db28ed
2 changed files with 86 additions and 61 deletions
|
|
@ -28,7 +28,7 @@ impl AsRef<[u8]> for Uri {
|
||||||
|
|
||||||
fn captured(caps: &Captures, name: &str) -> String {
|
fn captured(caps: &Captures, name: &str) -> String {
|
||||||
caps.name(name)
|
caps.name(name)
|
||||||
.unwrap_or_else(|| panic!("{name} not captured"))
|
.unwrap_or_else(|| panic!("{name:?} not captured"))
|
||||||
.as_str()
|
.as_str()
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +103,36 @@ mod tests {
|
||||||
test_util::check_trait,
|
test_util::check_trait,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_captured_works() {
|
||||||
|
let cases = [
|
||||||
|
// simple http host
|
||||||
|
("http://example.com", "http", "example.com"),
|
||||||
|
// https host with port
|
||||||
|
("https://my-host:8080", "https", "my-host:8080"),
|
||||||
|
// trailing slash
|
||||||
|
("scheme://host/", "scheme", "host"),
|
||||||
|
// with path
|
||||||
|
("scheme://host/path/to/whatever", "scheme", "host"),
|
||||||
|
// custom scheme
|
||||||
|
("custom+scheme://host", "custom+scheme", "host"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (good, scheme, host) in cases {
|
||||||
|
let caps = SHARRY_URI_RE.captures(good).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(captured(&caps, "scheme"), scheme);
|
||||||
|
assert_eq!(captured(&caps, "host"), host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "\"foo\" not captured"]
|
||||||
|
fn make_captured_panic() {
|
||||||
|
let caps = SHARRY_URI_RE.captures("http://example.com").unwrap();
|
||||||
|
captured(&caps, "foo");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_traits_working() {
|
fn basic_traits_working() {
|
||||||
let cases = [
|
let cases = [
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,6 @@ impl From<bool> for FileID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::Parameter;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn true_makes_valids() {
|
fn true_makes_valids() {
|
||||||
let uri = Uri::from(true);
|
let uri = Uri::from(true);
|
||||||
|
|
@ -141,6 +135,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn false_makes_invalids() {
|
fn false_makes_invalids() {
|
||||||
|
use crate::Parameter;
|
||||||
|
|
||||||
fn test_check(value: impl CheckID, callback: impl FnOnce(&Parameter) -> bool) {
|
fn test_check(value: impl CheckID, callback: impl FnOnce(&Parameter) -> bool) {
|
||||||
let check = value.check().unwrap_err();
|
let check = value.check().unwrap_err();
|
||||||
let p = check.get_invalid_param().unwrap();
|
let p = check.get_invalid_param().unwrap();
|
||||||
|
|
@ -178,4 +174,3 @@ mod tests {
|
||||||
test_check((&share_id_i, &file_id), is_share_id_i);
|
test_check((&share_id_i, &file_id), is_share_id_i);
|
||||||
test_check((&share_id, &file_id_i), is_file_id_i);
|
test_check((&share_id, &file_id_i), is_file_id_i);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue