diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/http/tests/status_code.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/http/tests/status_code.rs')
| -rw-r--r-- | vendor/http/tests/status_code.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/vendor/http/tests/status_code.rs b/vendor/http/tests/status_code.rs new file mode 100644 index 00000000..0a962398 --- /dev/null +++ b/vendor/http/tests/status_code.rs @@ -0,0 +1,82 @@ +use http::*; + +#[test] +fn from_bytes() { + for ok in &[ + "100", "101", "199", "200", "250", "299", "321", "399", "499", "599", "600", "999", + ] { + assert!(StatusCode::from_bytes(ok.as_bytes()).is_ok()); + } + + for not_ok in &[ + "0", "00", "10", "40", "99", "000", "010", "099", "1000", "1999", + ] { + assert!(StatusCode::from_bytes(not_ok.as_bytes()).is_err()); + } +} + +#[test] +fn equates_with_u16() { + let status = StatusCode::from_u16(200u16).unwrap(); + assert_eq!(200u16, status); + assert_eq!(status, 200u16); +} + +#[test] +fn roundtrip() { + for s in 100..1000 { + let sstr = s.to_string(); + let status = StatusCode::from_bytes(sstr.as_bytes()).unwrap(); + assert_eq!(s, u16::from(status)); + assert_eq!(sstr, status.as_str()); + } +} + +#[test] +fn is_informational() { + assert!(status_code(100).is_informational()); + assert!(status_code(199).is_informational()); + + assert!(!status_code(200).is_informational()); +} + +#[test] +fn is_success() { + assert!(status_code(200).is_success()); + assert!(status_code(299).is_success()); + + assert!(!status_code(199).is_success()); + assert!(!status_code(300).is_success()); +} + +#[test] +fn is_redirection() { + assert!(status_code(300).is_redirection()); + assert!(status_code(399).is_redirection()); + + assert!(!status_code(299).is_redirection()); + assert!(!status_code(400).is_redirection()); +} + +#[test] +fn is_client_error() { + assert!(status_code(400).is_client_error()); + assert!(status_code(499).is_client_error()); + + assert!(!status_code(399).is_client_error()); + assert!(!status_code(500).is_client_error()); +} + +#[test] +fn is_server_error() { + assert!(status_code(500).is_server_error()); + assert!(status_code(599).is_server_error()); + + assert!(!status_code(499).is_server_error()); + assert!(!status_code(600).is_server_error()); +} + +/// Helper method for readability +fn status_code(status_code: u16) -> StatusCode { + StatusCode::from_u16(status_code).unwrap() +} |
