6 Commits

Author SHA1 Message Date
c734c582d4 fix for newest carp 2022-01-27 12:01:03 +01:00
03aab46ab5 update docs 2021-01-19 10:56:58 +01:00
4bf3e1c7c1 fix for new carp 2021-01-19 10:55:37 +01:00
2d62dee4d0 docs: fix links between absolute? and relative? 2020-05-09 22:06:20 +02:00
3eb542bdfd simplify tests 2020-05-05 14:33:45 +02:00
5b87d0bf9a fix tests for new version of carp 2020-05-05 13:57:56 +02:00
5 changed files with 467 additions and 468 deletions

View File

@@ -5,7 +5,7 @@ is a simple file path library for Carp.
## Installation
```clojure
(load "https://veitheller.de/git/carpentry/path@0.0.2")
(load "git@git.veitheller.de:carpentry/path.git@0.0.4")
```
### Usage
@@ -16,7 +16,7 @@ has some functions to work with the `PATH` environment variable.
It assumes either Windows or POSIX-style separators.
Look at [the documentation](https://veitheller.de/path) for more information.
Look at [the documentation](https://carpentry.dev/path) for more information.
<hr/>

View File

@@ -9,8 +9,8 @@
<body>
<div class="content">
<div class="logo">
<a href="http://github.com/carp-lang/Carp">
<img src="logo.png">
<a href="">
<img src="">
</a>
<div class="title">
path
@@ -25,13 +25,14 @@
</ul>
</div>
</div>
<div class="module">
<h1>
Path
</h1>
<div class="module-description">
<p>is a simple file path library for Carp.</p>
<h2>Installation</h2>
<pre><code class="language-clojure">(load &quot;https://veitheller.de/git/carpentry/path@0.0.2&quot;)
<pre><code class="language-clojure">(load &quot;git@git.veitheller.de:carpentry/path.git@0.0.4&quot;)
</code></pre>
<h3>Usage</h3>
<p>The <code>Path</code> module mostly operates on <code>String</code> arguments. It allows you to
@@ -50,7 +51,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[a, b] String)
(Fn [a, b] String)
</p>
<pre class="args">
(&lt;/&gt; before after)
@@ -70,7 +71,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Maybe String))
(Fn [(Ref String a)] (Maybe String))
</p>
<pre class="args">
(absolute p)
@@ -90,14 +91,14 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[(Ref String a)] Bool)
(Fn [(Ref String a)] Bool)
</p>
<pre class="args">
(absolute? p)
</pre>
<p class="doc">
<p>checks whether a path is absolute.</p>
<p>As such, it is the inverse to <a href="#relative">relative</a>.</p>
<p>As such, it is the inverse to <a href="#relative?">relative?</a>.</p>
</p>
</div>
@@ -111,7 +112,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[(Ref String a), (Ref String b)] String)
(Fn [(Ref String a), (Ref String b)] String)
</p>
<pre class="args">
(add-extension p ext)
@@ -131,7 +132,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[(Ref String a)] String)
(Fn [(Ref String a)] String)
</p>
<pre class="args">
(basename p)
@@ -151,7 +152,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
defn
</div>
<p class="sig">
[] (Maybe String))
(Fn [] (Maybe String))
</p>
<pre class="args">
(cwd)
@@ -172,7 +173,7 @@ which it can fail are OS-dependent, but it should happen relatively rare.</p>
defn
</div>
<p class="sig">
[(Ref String a)] String)
(Fn [(Ref String a)] String)
</p>
<pre class="args">
(drop-extension p)
@@ -193,7 +194,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Maybe String))
(Fn [(Ref String a)] (Maybe String))
</p>
<pre class="args">
(extension p)
@@ -213,7 +214,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Maybe String))
(Fn [(Ref String a)] (Maybe String))
</p>
<pre class="args">
(filename p)
@@ -234,7 +235,7 @@ is none.</p>
defn
</div>
<p class="sig">
[] (Maybe (Array String)))
(Fn [] (Maybe (Array String)))
</p>
<pre class="args">
(get-search-path)
@@ -254,7 +255,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a)] Bool)
(Fn [(Ref String a)] Bool)
</p>
<pre class="args">
(has-extension? p)
@@ -274,7 +275,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a), (Ref String b)] Bool)
(Fn [(Ref String a), (Ref String b)] Bool)
</p>
<pre class="args">
(is-extension? p ext)
@@ -294,7 +295,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref (Array String) a)] String)
(Fn [(Ref (Array String) a)] String)
</p>
<pre class="args">
(join ps)
@@ -335,14 +336,14 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a)] Bool)
(Fn [(Ref String a)] Bool)
</p>
<pre class="args">
(relative? p)
</pre>
<p class="doc">
<p>checks whether a path is relative.</p>
<p>As such, it is the inverse to <a href="#absolute">absolute</a>.</p>
<p>As such, it is the inverse to <a href="#absolute?">absolute?</a>.</p>
</p>
</div>
@@ -356,7 +357,7 @@ is none.</p>
defn
</div>
<p class="sig">
[(Ref String a), (Ref String b)] String)
(Fn [(Ref String a), (Ref String b)] String)
</p>
<pre class="args">
(replace-extension p ext)
@@ -398,7 +399,7 @@ variable we use on this OS.</p>
defn
</div>
<p class="sig">
[Char] Bool)
(Fn [Char] Bool)
</p>
<pre class="args">
(search-path-separator? c)
@@ -437,7 +438,7 @@ variable we use on this OS.</p>
defn
</div>
<p class="sig">
[(Ref Char StaticLifetime)] Bool)
(Fn [(Ref Char StaticLifetime)] Bool)
</p>
<pre class="args">
(separator? c)
@@ -478,7 +479,7 @@ variable we use on this OS.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Array String))
(Fn [(Ref String a)] (Array String))
</p>
<pre class="args">
(split p)
@@ -499,7 +500,7 @@ variable we use on this OS.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Maybe (Pair String String)))
(Fn [(Ref String a)] (Maybe (Pair String String)))
</p>
<pre class="args">
(split-extension p)
@@ -536,7 +537,7 @@ the extension.</p>
defn
</div>
<p class="sig">
[(Ref String a)] (Array String))
(Fn [(Ref String a)] (Array String))
</p>
<pre class="args">
(split-search-path p)
@@ -547,5 +548,6 @@ the extension.</p>
</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -1,13 +1,10 @@
(load "path.carp")
(defndynamic gendocs []
(do
(Project.config "title" "path")
(Project.config "docs-directory" "./docs/")
(Project.config "docs-logo" "")
(Project.config "docs-styling" "style.css")
(Project.config "docs-generate-index" false)
(save-docs Path)))
(save-docs Path)
(gendocs)
(quit)

View File

@@ -3,7 +3,7 @@
## Installation
```clojure
(load \"https://veitheller.de/git/carpentry/path@0.0.2\")
(load \"git@git.veitheller.de:carpentry/path.git@0.0.4\")
```
### Usage
@@ -16,7 +16,7 @@ It assumes either Windows or POSIX-style separators.")
(defmodule Path
(doc absolute? "checks whether a path is absolute.
As such, it is the inverse to [relative](#relative).")
As such, it is the inverse to [relative?](#relative?).")
(doc separator "is the default separator we use on this OS.")
(doc separators "is the possible separators we could use on this OS.")
(doc search-path-separator "is the separator for the `PATH` environment
@@ -32,7 +32,7 @@ variable we use on this OS.")
(def search-path-separator \;)
(def extension-pat #"\.[^\\/\.]*$")
(def sep-string "\\"))
(not-on-windows
(posix-only
(defn absolute? [p] (String.starts-with? p "/"))
(def separator \/)
(def separators [\/])
@@ -42,7 +42,7 @@ variable we use on this OS.")
(doc relative? "checks whether a path is relative.
As such, it is the inverse to [absolute](#absolute).")
As such, it is the inverse to [absolute?](#absolute?).")
(defn relative? [p] (not (absolute? p)))
(doc separator? "checks whether the character `c` is a path separator on this
@@ -127,9 +127,9 @@ Examples on POSIX:
(doc drop-extension "drops the extension of a path `p`. Does nothing if there
is none.")
(defn drop-extension [p]
@(match (split-extension p)
(Maybe.Nothing) p
(Maybe.Just pair) (Pair.a &pair)))
(match (split-extension p)
(Maybe.Nothing) @p
(Maybe.Just pair) @(Pair.a &pair)))
(doc add-extension "adds an extension `ext` to a path `p`.")
(defn add-extension [p ext] (String.concat &[@p @"." @ext]))
@@ -148,5 +148,5 @@ an extension if there previously was none.")
(defn split-search-path [p] (String.split-by p &[search-path-separator]))
(doc get-search-path "gets the `PATH` environment variable and splits it.")
(defn get-search-path []
(Maybe.apply (IO.getenv @"PATH") &(fn [p] (split-search-path &p))))
(Maybe.apply (IO.getenv "PATH") &(fn [p] (split-search-path &p))))
)

View File

@@ -3,7 +3,7 @@
(use-all Path Test)
(if (not (Dynamic.or (= "windows" (os)) (= "mingw32" (os))))
(posix-only
(deftest test
(assert-equal test
"path/joined"
@@ -41,11 +41,11 @@
"cwd works"
)
; TODO why does this test not work?
;(assert-equal test
; "file"
; &(drop-extension "file.txt")
; "drop-extension works if there is an extension"
;)
(assert-equal test
"file"
&(drop-extension "file.txt")
"drop-extension works if there is an extension"
)
(assert-equal test
"file"
&(drop-extension "file")
@@ -87,7 +87,7 @@
)
)
())
(if (Dynamic.or (= "windows" (os)) (= "mingw32" (os)))
(windows-only
(deftest test
(assert-true test
false