48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use servme::UrlExtract;
|
|
|
|
#[test]
|
|
fn param_str() {
|
|
let uri = "https://example.com/path?param1=value1¶m2=value2¶m3=value%203"
|
|
.parse()
|
|
.unwrap();
|
|
let extractor = UrlExtract::new(&uri);
|
|
|
|
assert_eq!(extractor.param_str("param1"), Some("value1".to_string()));
|
|
assert_eq!(extractor.param_str("param2"), Some("value2".to_string()));
|
|
assert_eq!(extractor.param_str("param3"), Some("value 3".to_string()));
|
|
assert_eq!(extractor.param_str("nonexistent"), None);
|
|
}
|
|
|
|
#[test]
|
|
fn param_i64() {
|
|
let uri = "https://example.com/path?param1=42¶m2=invalid"
|
|
.parse()
|
|
.unwrap();
|
|
let extractor = UrlExtract::new(&uri);
|
|
|
|
assert_eq!(extractor.param_i64("param1"), Some(42));
|
|
assert_eq!(extractor.param_i64("param2"), None);
|
|
assert_eq!(extractor.param_i64("nonexistent"), None);
|
|
}
|
|
|
|
#[test]
|
|
fn param_f64() {
|
|
let uri = "https://example.com/path?param1=3.14¶m2=invalid"
|
|
.parse()
|
|
.unwrap();
|
|
let extractor = UrlExtract::new(&uri);
|
|
|
|
assert_eq!(extractor.param_f64("param1"), Some(3.14));
|
|
assert_eq!(extractor.param_f64("param2"), None);
|
|
assert_eq!(extractor.param_f64("nonexistent"), None);
|
|
}
|
|
|
|
#[test]
|
|
fn url_i64() {
|
|
let uri = "https://example.com/path/42/rest".parse().unwrap();
|
|
assert_eq!(UrlExtract::url_i64(&uri, "/path/"), Some(42));
|
|
|
|
let uri_without_match = "https://example.com/otherpath/42/rest".parse().unwrap();
|
|
assert_eq!(UrlExtract::url_i64(&uri_without_match, "/path/"), None);
|
|
}
|