summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-06-02 12:56:41 +0300
committerA Farzat <a@farzat.xyz>2026-06-02 12:56:41 +0300
commit9dc2499bcdaa961a42ccee59025d6d52a296bbdf (patch)
tree625b2fb5e0613e7ff2a8b9d2c11812d72572e1e6 /src
parentab96459166b866c91dce7295f00efd9e4958d1df (diff)
downloadrepo2markdown-9dc2499bcdaa961a42ccee59025d6d52a296bbdf.tar.gz
repo2markdown-9dc2499bcdaa961a42ccee59025d6d52a296bbdf.zip
Start by normalizing user input filenames
The filenames displayed in the output markdown should be consistent, regardless of the way they were input to the program (absolute, relative). They should always be relative to the project root.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..0d7a010
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,43 @@
+use std::path::{Path, PathBuf};
+
+#[derive(Debug)]
+pub enum NormalizeError {
+ EmptyInput,
+}
+
+pub fn normalize_path(
+ _root: &Path,
+ _origin: &Path,
+ input: &Path,
+) -> Result<PathBuf, NormalizeError> {
+ if input.as_os_str().is_empty() {
+ return Err(NormalizeError::EmptyInput);
+ }
+ Ok(input.to_path_buf())
+}
+
+#[cfg(test)]
+mod tests {
+ use std::path::Path;
+
+ use super::{NormalizeError, normalize_path};
+
+ #[test]
+ fn empty_path_returns_error() {
+ let root = Path::new("/project");
+ let origin_dir = Path::new("/project");
+ let input = Path::new("");
+ let result = normalize_path(root, origin_dir, input);
+ assert!(matches!(result, Err(NormalizeError::EmptyInput)));
+ }
+
+ #[test]
+ fn plain_filename_with_root_at_cwd_returns_filename() {
+ let root = Path::new("/project");
+ let origin_dir = Path::new("/project");
+ let input = Path::new("main.rs");
+ let result = normalize_path(root, origin_dir, input);
+ assert!(result.is_ok());
+ assert_eq!(result.unwrap(), Path::new("main.rs"));
+ }
+}