test: add basic tests for URL
This commit is contained in:
parent
61ab4ba38d
commit
8bc33130a9
1 changed files with 33 additions and 0 deletions
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue