use irondrop::utils::get_request_path;
#[test]
fn test_get_request_path_variants() {
assert_eq!(get_request_path("GET /abc HTTP/1.1"), "abc");
assert_eq!(get_request_path("GET / HTTP/1.1"), "/");
assert_eq!(get_request_path("GET abc HTTP/1.1"), "abc");
assert_eq!(get_request_path("GET /abc"), "abc");
assert_eq!(get_request_path("POST /p HTTP/1.1"), "/");
}
#[test]
fn test_get_request_path_edge_cases() {
assert_eq!(get_request_path(""), "/");
assert_eq!(get_request_path("GET"), "/");
assert_eq!(get_request_path("GET "), "/");
assert_eq!(get_request_path("INVALID REQUEST"), "/");
assert_eq!(get_request_path("GET /path HTTP/1.1"), "path");
}
#[test]
fn test_get_request_path_special_characters() {
assert_eq!(
get_request_path("GET /path?param=value HTTP/1.1"),
"path?param=value"
);
assert_eq!(
get_request_path("GET /path#fragment HTTP/1.1"),
"path#fragment"
);
assert_eq!(
get_request_path("GET /path%20with%20spaces HTTP/1.1"),
"path%20with%20spaces"
);
assert_eq!(
get_request_path("GET /path/with-special_chars.html HTTP/1.1"),
"path/with-special_chars.html"
);
}
#[test]
fn test_get_request_path_different_methods() {
assert_eq!(get_request_path("POST /upload HTTP/1.1"), "/");
assert_eq!(get_request_path("PUT /resource HTTP/1.1"), "/");
assert_eq!(get_request_path("DELETE /item HTTP/1.1"), "/");
assert_eq!(get_request_path("HEAD /info HTTP/1.1"), "/");
assert_eq!(get_request_path("OPTIONS /options HTTP/1.1"), "/");
assert_eq!(get_request_path("PATCH /update HTTP/1.1"), "/");
}
#[test]
fn test_get_request_path_http_versions() {
assert_eq!(get_request_path("GET /path HTTP/1.0"), "path");
assert_eq!(get_request_path("GET /path HTTP/1.1"), "path");
assert_eq!(get_request_path("GET /path HTTP/2.0"), "path");
assert_eq!(get_request_path("GET /path HTTP/INVALID"), "path");
assert_eq!(get_request_path("GET /path"), "path");
}
#[test]
fn test_get_request_path_case_sensitivity() {
assert_eq!(get_request_path("get /path HTTP/1.1"), "/");
assert_eq!(get_request_path("Get /path HTTP/1.1"), "/");
assert_eq!(get_request_path("GEt /path HTTP/1.1"), "/");
assert_eq!(get_request_path("GET /path HTTP/1.1"), "path"); }
#[test]
fn test_get_request_path_long_paths() {
let long_path = "/".to_string() + &"a".repeat(1000);
let request = format!("GET {} HTTP/1.1", long_path);
let expected = long_path.trim_start_matches('/');
assert_eq!(get_request_path(&request), expected);
}
#[test]
fn test_get_request_path_unicode() {
assert_eq!(get_request_path("GET /файл.txt HTTP/1.1"), "файл.txt");
assert_eq!(get_request_path("GET /文件.html HTTP/1.1"), "文件.html");
assert_eq!(get_request_path("GET /café/résumé HTTP/1.1"), "café/résumé");
}
#[test]
fn test_get_request_path_whitespace_variations() {
assert_eq!(get_request_path("GET\t/path\tHTTP/1.1"), "/");
assert_eq!(get_request_path("GET / path / HTTP/1.1"), " path /");
assert_eq!(get_request_path("GET\n/path\nHTTP/1.1"), "/");
}