From a658ae86ace40a00a8476a19f55aca3fe72abd8a Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sat, 20 Jun 2026 04:39:33 +0300 Subject: Rename NormalizedPath's relative field root_relative provides better semantic clarity. --- src/normalizer.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/normalizer.rs') diff --git a/src/normalizer.rs b/src/normalizer.rs index 116cca1..3ad3da2 100644 --- a/src/normalizer.rs +++ b/src/normalizer.rs @@ -4,12 +4,12 @@ use std::{ path::{Component, Path, PathBuf}, }; -#[derive(PartialEq, Eq, Hash)] +#[derive(PartialEq, Eq, Hash, Clone)] pub struct NormalizedPath { /// Path normalized and made absolute, suitable for filesystem access pub absolute: PathBuf, - /// Path normalized and made relative to root, used as identifier - pub relative: PathBuf, + /// Path normalized and made relative to root, used as identifier and for display + pub root_relative: PathBuf, } #[derive(Debug)] @@ -66,7 +66,7 @@ impl Normalizer { let input = absolutize(input, &self.origin_base); let normalized_input = normalize_components(&input)?; Ok(NormalizedPath { - relative: make_relative_to_root(&normalized_input, &self.root), + root_relative: make_relative_to_root(&normalized_input, &self.root), absolute: normalized_input, }) } @@ -184,7 +184,7 @@ mod tests { let fake_cwd = Path::new("/sandbox"); let normalizer = Normalizer::new_with_cwd(Path::new(""), Path::new(""), fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); - assert_eq!(result.unwrap().relative, Path::new("main.rs")); + assert_eq!(result.unwrap().root_relative, Path::new("main.rs")); } #[test] @@ -194,7 +194,7 @@ mod tests { let origin_base = Path::new("src"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("../main.rs")); - assert_eq!(result.unwrap().relative, Path::new("main.rs")); + assert_eq!(result.unwrap().root_relative, Path::new("main.rs")); } #[test] @@ -204,7 +204,7 @@ mod tests { let origin_base = Path::new("/project/src"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); - assert_eq!(result.unwrap().relative, Path::new("src/main.rs")); + assert_eq!(result.unwrap().root_relative, Path::new("src/main.rs")); } #[test] @@ -214,7 +214,10 @@ mod tests { let origin_base = Path::new("/outside"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); - assert_eq!(result.unwrap().relative, Path::new("../outside/main.rs")); + assert_eq!( + result.unwrap().root_relative, + Path::new("../outside/main.rs") + ); } #[test] @@ -224,7 +227,10 @@ mod tests { let origin_base = Path::new("/sandbox/outside"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); - assert_eq!(result.unwrap().relative, Path::new("../outside/main.rs")); + assert_eq!( + result.unwrap().root_relative, + Path::new("../outside/main.rs") + ); } #[test] @@ -234,7 +240,7 @@ mod tests { let origin_base = Path::new("/sandbox/outside"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("/sandbox/main.rs")); - assert_eq!(result.unwrap().relative, Path::new("../main.rs")); + assert_eq!(result.unwrap().root_relative, Path::new("../main.rs")); } #[test] @@ -244,7 +250,10 @@ mod tests { let origin_base = Path::new("outside"); let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); - assert_eq!(result.unwrap().relative, Path::new("../outside/main.rs")); + assert_eq!( + result.unwrap().root_relative, + Path::new("../outside/main.rs") + ); } #[test] @@ -268,7 +277,7 @@ mod tests { let normalizer = Normalizer::new_with_cwd(root, origin_base, fake_cwd).unwrap(); let result = normalizer.normalize(Path::new("main.rs")); assert_eq!( - result.unwrap().relative, + result.unwrap().root_relative, Path::new("../sandbox/outside/main.rs") ); } -- cgit v1.3.1