Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion path.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
54 changes: 53 additions & 1 deletion test/path.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down