From 65078caa63d9b57119ca6def2af187a3e6841cac Mon Sep 17 00:00:00 2001 From: "carpentry-heartbeat[bot]" Date: Tue, 16 Jun 2026 13:53:12 +0200 Subject: [PATCH] Add tests for 8 untested public functions, fix has-extension? doc typo --- path.carp | 2 +- test/path.carp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/path.carp b/path.carp index f7a7e44..b44bfaf 100644 --- a/path.carp +++ b/path.carp @@ -116,7 +116,7 @@ Examples on POSIX: (doc extension "gets the extension of a file as a `Maybe`.") (defn extension [p] (Maybe.apply (split-extension p) &(fn [p] @(Pair.b &p)))) - (doc has-extension? "cheks whether the path `p` has an extension.") + (doc has-extension? "checks whether the path `p` has an extension.") (defn has-extension? [p] (Maybe.just? &(split-extension p))) (doc is-extension? "checks whether the path `p` has the extension `ext`.") (defn is-extension? [p ext] (= &(extension p) &(Maybe.Just @ext))) diff --git a/test/path.carp b/test/path.carp index 358e495..255d680 100644 --- a/test/path.carp +++ b/test/path.carp @@ -47,7 +47,59 @@ "is-extension? works if there is the wrong extension") (assert-false test (is-extension? "file" "txt") - "is-extension? works if there is no extension")) + "is-extension? works if there is no extension") + (assert-equal test + &[@"path" @"to" @"file"] + &(split "path/to/file") + "split works") + (assert-equal test + &[@"" @"usr" @"bin"] + &(split "/usr/bin") + "split works on absolute paths") + (assert-equal test + "path/to/file" + &(join &[@"path" @"to" @"file"]) + "join works") + (assert-equal test + &(Maybe.Just @"file.txt") + &(filename "path/to/file.txt") + "filename works") + (assert-equal test + &(Maybe.Just @"") + &(filename "") + "filename returns empty string for empty path") + (assert-equal test + &(Maybe.Just (Pair.init @"file" @"txt")) + &(split-extension "file.txt") + "split-extension works with extension") + (assert-equal test + &(Maybe.Nothing) + &(split-extension "file") + "split-extension works without extension") + (assert-equal test + &(Maybe.Just (Pair.init @"file/path.txt.bob" @"fred")) + &(split-extension "file/path.txt.bob.fred") + "split-extension gets last extension") + (assert-equal test + "file.ext" + &(replace-extension "file.txt" "ext") + "replace-extension works with existing extension") + (assert-equal test + "file.ext" + &(replace-extension "file" "ext") + "replace-extension works without existing extension") + (assert-true test (separator? &\/) "separator? works for /") + (assert-false test (separator? &\a) "separator? works for non-separator") + (assert-true test + (search-path-separator? \:) + "search-path-separator? works for :") + (assert-false test + (search-path-separator? \;) + "search-path-separator? works for non-separator") + (assert-equal test + &[@"/usr/bin" @"/usr/local/bin"] + &(split-search-path "/usr/bin:/usr/local/bin") + "split-search-path works")) ()) (windows-only (deftest test