Skip to content

Commit 6f33bfb

Browse files
committed
Add cstring_as_ascii_str test
1 parent 08faa34 commit 6f33bfb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ascii_str.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,19 @@ mod tests {
840840
assert_eq!(generic(&mut "A"), Ok(ascii_str));
841841
}
842842

843+
#[cfg(feature = "std")]
844+
#[test]
845+
fn cstring_as_ascii_str() {
846+
use std::ffi::{CStr, CString};
847+
fn generic<C: AsAsciiStr + ?Sized>(c: &C) -> Result<&AsciiStr, AsAsciiStrError> {
848+
c.as_ascii_str()
849+
}
850+
let arr = [AsciiChar::A];
851+
let ascii_str: &AsciiStr = arr.as_ref().into();
852+
let cstr = CString::new("A").unwrap();
853+
assert_eq!(generic(&*cstr), Ok(ascii_str));
854+
}
855+
843856
#[test]
844857
fn generic_as_mut_ascii_str() {
845858
fn generic_mut<C: AsMutAsciiStr + ?Sized>(

0 commit comments

Comments
 (0)