diff --git a/src/lib.rs b/src/lib.rs index 771b3a6..0e8ec7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,7 +78,7 @@ use std::cell::Cell; use std::ffi::CString; use std::path::{Path, PathBuf}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum Error { CouldNotOpenFile(std::path::PathBuf, FileMode), CouldNotReadAtomNumber(u32), @@ -145,7 +145,7 @@ impl Error { impl std::error::Error for Error {} -pub type Result = std::result::Result; +pub type Result = std::result::Result; #[derive(Debug, Clone, PartialEq)] pub enum FileMode { @@ -579,4 +579,16 @@ mod tests { } Ok(()) } + + #[test] + fn test_path_to_cstring() -> Result<(), Box> { + let result_invalid = path_to_cstring("invalid/\0path"); + + assert_eq!(result_invalid, Err(Error::PathInvalidCstring)); + + let result_valid = path_to_cstring("valid/path"); + + assert_eq!(result_valid, Ok(CString::new("valid/path")?)); + Ok(()) + } }