From e95fea3bfc5bec399ef554dcf343972cf2934c63 Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Mon, 9 Nov 2020 17:33:03 +1100 Subject: [PATCH] Unit test for path_to_cstring() --- src/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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(()) + } }