test: add basic tests for URL

This commit is contained in:
Compositr 2024-11-04 22:23:13 +11:00
parent 61ab4ba38d
commit 8bc33130a9

View file

@ -112,3 +112,36 @@ impl Request {
self.stream self.stream
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_url_new() {
let url = URL::new("/".to_string()).unwrap();
assert_eq!(url.path, "/");
assert_eq!(url.raw, "/");
let url = URL::new("/path/to/resource".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource");
let url = URL::new("/path/to/resource?query=string".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource");
assert_eq!(url.query.len(), 1);
assert_eq!(url.query.get("query").unwrap(), "string");
let url = URL::new("/path/to/resource?query=string&another=one".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource");
assert_eq!(url.query.len(), 2);
assert_eq!(url.query.get("query").unwrap(), "string");
assert_eq!(url.query.get("another").unwrap(), "one");
let url = URL::new("/path/to/resource?query=string&another=one&third=3".to_string()).unwrap();
assert_eq!(url.path, "/path/to/resource");
assert_eq!(url.query.len(), 3);
assert_eq!(url.query.get("query").unwrap(), "string");
assert_eq!(url.query.get("another").unwrap(), "one");
assert_eq!(url.query.get("third").unwrap(), "3");
}
}