From 289596175fa5895877b78dd43d1a256c360fdc49 Mon Sep 17 00:00:00 2001 From: "Kevin M. Gill" Date: Sun, 2 Apr 2023 16:36:05 -0700 Subject: [PATCH] Moved method cwd() from MRU, plus some tests --- src/path.rs | 8 ++++++++ tests/path.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/path.rs diff --git a/src/path.rs b/src/path.rs index 0056cd1..d218fb2 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,3 +1,4 @@ +use std::env; use std::ffi::OsStr; use std::path::Path; @@ -46,3 +47,10 @@ pub fn parent_writable(chk_path: &str) -> bool { pub fn parent_exists_and_writable(chk_path: &str) -> bool { parent_exists(chk_path) && parent_writable(chk_path) } + +pub fn cwd() -> String { + match env::current_dir().unwrap().as_os_str().to_str() { + Some(d) => String::from(d), + None => String::from("./"), + } +} diff --git a/tests/path.rs b/tests/path.rs new file mode 100644 index 0000000..1a02072 --- /dev/null +++ b/tests/path.rs @@ -0,0 +1,26 @@ +use sciimg::path; + +#[test] +fn test_file_exists() { + assert!(path::file_exists("Cargo.toml")); +} + +#[test] +fn test_file_writable() { + assert!(path::file_writable("Cargo.toml")); +} + +#[test] +fn test_parent_exists() { + assert!(path::parent_exists("Cargo.toml")); +} + +#[test] +fn test_parent_writable() { + assert!(path::parent_writable("Cargo.toml")); +} + +#[test] +fn test_parent_exists_and_writable() { + assert!(path::parent_exists_and_writable("Cargo.toml")); +}