Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aliases: ns->path and path->ns #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/fs/core.clj
Expand Up @@ -398,7 +398,7 @@ If 'trim-ext' is true, any extension is trimmed."
of the second."
[p c] (some #{(file p)} (parents c)))

(defn ns-path
(defn ns->path
"Takes a namespace symbol and creates a path to it. Replaces hyphens with
underscores. Assumes the path should be relative to cwd."
[n]
Expand All @@ -408,7 +408,7 @@ If 'trim-ext' is true, any extension is trimmed."
(replace \. \/))
".clj")))

(defn path-ns
(defn path->ns
"Takes a path to a Clojure file and constructs a namespace symbol
out of the path."
[path]
Expand Down Expand Up @@ -448,3 +448,5 @@ If 'trim-ext' is true, any extension is trimmed."
[path]
(set! *cwd* (file path)))

(def ns-path ns->path)
(def path-ns path->ns)
4 changes: 2 additions & 2 deletions test/fs/core_test.clj
Expand Up @@ -301,10 +301,10 @@
(child-of? "/foo/bar/baz" "/foo/bar") => falsey)

(fact
(path-ns "foo/bar/baz_quux.clj") => 'foo.bar.baz-quux)
(path->ns "foo/bar/baz_quux.clj") => 'foo.bar.baz-quux)

(fact
(str (ns-path 'foo.bar.baz-quux)) => (has-suffix "foo/bar/baz_quux.clj"))
(str (ns->path 'foo.bar.baz-quux)) => (has-suffix "foo/bar/baz_quux.clj"))

(fact
(absolute? "/foo/bar") => true
Expand Down