Skip to content

Commit

Permalink
fix: cut by last src
Browse files Browse the repository at this point in the history
  • Loading branch information
ProbablyClem committed Jan 25, 2024
1 parent 865d0cb commit 1a531da
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion utoipauto-core/src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ pub fn extract_module_name_from_path(path: &str) -> String {
// When using cargo workspaces, paths may look like `./subcrate/src/my/module`,
// `./crates/subcrate/src/my/module`, etc., so we need to remove anything up to `src`
// (or `tests`) to still produce `crate::my::module`.
// So we split the segments by the last occurrence of `src` or `tests` and take the last part.
let segments_inside_crate = match segments
.iter()
.position(|&segment| segment == "src" || segment == "tests")
.rposition(|&segment| segment == "src" || segment == "tests")
{
Some(idx) => &segments[(idx + 1)..],
None => &segments,
Expand Down Expand Up @@ -149,4 +150,12 @@ mod tests {
"crate::routing::api::audio"
);
}

#[test]
fn test_extract_module_name_from_folders_nested() {
assert_eq!(
extract_module_name_from_path("./src/applications/src/retail_api/controllers/mod.rs"),
"crate::retail_api::controllers"
);
}
}

0 comments on commit 1a531da

Please sign in to comment.