aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index a7e945a..556bad3 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -125,6 +125,13 @@ pub fn current_working_directory() -> PathBuf {
125 std::env::current_dir().expect("Failed to obtain current working directory") 125 std::env::current_dir().expect("Failed to obtain current working directory")
126} 126}
127 127
128pub fn path_ends_with_slash(path: impl AsRef<Path>) -> bool {
129 path.as_ref()
130 .to_str()
131 .map(|s| s.ends_with('/'))
132 .unwrap_or_default()
133}
134
128#[cfg(test)] 135#[cfg(test)]
129mod tests { 136mod tests {
130 use super::*; 137 use super::*;
@@ -153,4 +160,19 @@ mod tests {
153 weakly_canonical_cwd("configs/nvim/lua/setup.lua", cwd) 160 weakly_canonical_cwd("configs/nvim/lua/setup.lua", cwd)
154 ); 161 );
155 } 162 }
163
164 #[test]
165 fn test_path_ends_with_slash() {
166 assert!(!path_ends_with_slash(""));
167 assert!(!path_ends_with_slash("/f1"));
168 assert!(!path_ends_with_slash("/f1/f2"));
169 assert!(!path_ends_with_slash("./f1/f2"));
170 assert!(!path_ends_with_slash("./f1/f2/../f3"));
171
172 assert!(path_ends_with_slash("/"));
173 assert!(path_ends_with_slash("/f1/"));
174 assert!(path_ends_with_slash("f1/"));
175 assert!(path_ends_with_slash("f1/f2/"));
176 assert!(path_ends_with_slash("f1/f2/../f3/"));
177 }
156} 178}