summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-11-14 21:39:00 +0200
committerLars Wirzenius <liw@liw.fi>2023-11-14 21:39:00 +0200
commit6df32bca34033baad8704326caf928c681170abe (patch)
tree6358140f8ceade519b1cf1511d6053eb19a8241a
parente412a594ef83e164e12a4da38be83101a3c08ac2 (diff)
downloadpathdedup-6df32bca34033baad8704326caf928c681170abe.tar.gz
dedup
Signed-off-by: Lars Wirzenius <liw@liw.fi> Sponsored-by: author
-rw-r--r--src/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index a1e2a8a..bf1e801 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,15 @@ fn main() -> anyhow::Result<()> {
}
fn pathdedup(path: &str) -> String {
- path.into()
+ let mut elements: Vec<&str> = vec![];
+
+ for e in path.split(':') {
+ if !elements.contains(&e) {
+ elements.push(e);
+ }
+ }
+
+ elements.join(".")
}
#[cfg(test)]
@@ -15,4 +23,14 @@ mod test {
fn empty_string() {
assert_eq!(pathdedup(""), "");
}
+
+ #[test]
+ fn single_element() {
+ assert_eq!(pathdedup("/foo"), "/foo");
+ }
+
+ #[test]
+ fn duplicate_elements() {
+ assert_eq!(pathdedup("/foo:/foo"), "/foo");
+ }
}