Skip to content

Commit e7162e8

Browse files
committed
test(globals): add sapi header test
Refs: #441
1 parent 00c43bd commit e7162e8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/zend/globals.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,36 @@ impl<T> DerefMut for GlobalWriteGuard<T> {
835835
self.globals
836836
}
837837
}
838+
839+
#[cfg(feature = "embed")]
840+
#[cfg(test)]
841+
mod embed_tests {
842+
use crate::embed::Embed;
843+
use std::os::raw::c_char;
844+
845+
use super::SapiHeader;
846+
847+
#[test]
848+
fn test_sapi_header() {
849+
Embed::run(|| {
850+
let headers = [
851+
("Content-Type: text/html", "Content-Type", "text/html"),
852+
("X: Custom:Header", "X", "Custom:Header"),
853+
];
854+
855+
for (header_text, name, value) in headers {
856+
let header = SapiHeader {
857+
header: header_text.as_bytes().as_ptr() as *mut c_char,
858+
header_len: header_text.len(),
859+
};
860+
assert_eq!(header.name(), name, "Header name mismatch");
861+
assert_eq!(header.value(), Some(value), "Header value mismatch");
862+
assert_eq!(
863+
header.as_str(),
864+
format!("{name}: {value}"),
865+
"Header string mismatch"
866+
);
867+
}
868+
});
869+
}
870+
}

0 commit comments

Comments
 (0)