|
| 1 | +use std::{fs, str::FromStr}; |
| 2 | + |
| 3 | +use http_message::PartialHttpRequest; |
| 4 | + |
| 5 | +use pretty_assertions::assert_eq; |
| 6 | + |
| 7 | +test!(display_empty_request, "./tests/fixtures/empty.request"); |
| 8 | +test!( |
| 9 | + display_get_with_headers_request, |
| 10 | + "./tests/fixtures/get_with_headers.request" |
| 11 | +); |
| 12 | +test!( |
| 13 | + display_get_with_multiple_spaces_request, |
| 14 | + "./tests/fixtures/get_with_multiple_spaces.request" |
| 15 | +); |
| 16 | +test!( |
| 17 | + display_get_without_http_version_request, |
| 18 | + "./tests/fixtures/get_without_http_version.request" |
| 19 | +); |
| 20 | +test!(display_get_request, "./tests/fixtures/get.request"); |
| 21 | +test!( |
| 22 | + display_post_with_body_request, |
| 23 | + "./tests/fixtures/post_with_body.request" |
| 24 | +); |
| 25 | +test!( |
| 26 | + display_post_with_headers_and_body_request, |
| 27 | + "./tests/fixtures/post_with_headers_and_body.request" |
| 28 | +); |
| 29 | +test!( |
| 30 | + display_whitespace_request, |
| 31 | + "./tests/fixtures/whitespace.request" |
| 32 | +); |
| 33 | + |
| 34 | +#[macro_export] |
| 35 | +macro_rules! test { |
| 36 | + ($name:ident, $path:expr) => { |
| 37 | + #[test] |
| 38 | + fn $name() { |
| 39 | + let path: &str = $path; |
| 40 | + let content = fs::read_to_string(path).expect("should read test fixture"); |
| 41 | + |
| 42 | + let partial = PartialHttpRequest::from_str(&content).expect("should be parsable"); |
| 43 | + |
| 44 | + assert_eq!(content, format!("{partial}")); |
| 45 | + } |
| 46 | + }; |
| 47 | +} |
0 commit comments