summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.ert-runner3
-rw-r--r--Cask1
-rw-r--r--README.md103
-rw-r--r--README.md.tpl62
-rw-r--r--f.el93
-rw-r--r--test/f-destructive-test.el33
-rw-r--r--test/f-init.el4
-rw-r--r--test/f-io-test.el35
-rw-r--r--test/f-misc-test.el38
-rw-r--r--test/f-predicates-test.el83
10 files changed, 316 insertions, 139 deletions
diff --git a/.ert-runner b/.ert-runner
index cf8a705..f2ebff7 100644
--- a/.ert-runner
+++ b/.ert-runner
@@ -1 +1,2 @@
--l test/f-init.el \ No newline at end of file
+-l test/f-init.el
+--reporter dot
diff --git a/Cask b/Cask
index 009d3df..80771cf 100644
--- a/Cask
+++ b/Cask
@@ -5,6 +5,7 @@
(development
(depends-on "ert-runner")
+ (depends-on "ert-async")
(depends-on "s")
(depends-on "dash")
(depends-on "cask")
diff --git a/README.md b/README.md
index db10611..be72f48 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,8 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-write-bytes](#f-write-bytes-data-path) `(data path)`
* [f-read-text](#f-read-text-path-optional-coding) `(path &optional coding)`
* [f-write-text](#f-write-text-text-coding-path)`(text coding path)`
+* [f-append-text](#f-append-text-text-coding-path)`(text coding path)`
+* [f-append-bytes](#f-append-data-path)`(text coding path)`
### Destructive
@@ -51,6 +53,7 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-symlink](#f-symlink-source-path) `(source path)`
* [f-move](#f-move-from-to) `(from to)`
* [f-copy](#f-copy-from-to) `(from to)`
+* [f-copy-contenst](#f-copy-contents-from-to) `(from to)`
* [f-touch](#f-touch-path) `(path)`
### Predicates
@@ -71,6 +74,7 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-child-of?](#f-child-of-path-a-path-b) `(path-a path-b)`
* [f-ancestor-of?](#f-ancestor-of-path-a-path-b) `(path-a path-b)`
* [f-descendant-of?](#f-descendant-of-path-a-path-b) `(path-a path-b)`
+* [f-hidden?](#f-hidden-path) `(path)`
### Stats
@@ -86,7 +90,6 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-directories](#f-directories-path-optional-fn-recursive) `(path &optional fn recursive)`
* [f-files](#f-files-path-optional-fn-recursive) `(path &optional fn recursive)`
* [f-root](#f-root-) `()`
-* [f-up](#f-up-fn-optional-dir) `(fn &optional dir)`
* [f-traverse-upwards](#f-traverse-upwards-fn-optional-path) `(fn &optional path)`
* [f-with-sandbox](#f-with-sandbox-path-or-paths-rest-body) `(path-or-paths &rest body)`
@@ -114,7 +117,7 @@ Split PATH and return list containing parts.
### f-expand `(path &optional dir)`
-Expand PATH relative to DIR (or `default-directory').
+Expand PATH relative to DIR (or ‘default-directory’).
```lisp
(f-expand "name") ;; => "/default/directory/name"
@@ -157,7 +160,7 @@ Return the deepest common parent directory of PATHS.
Return the file extension of PATH.
The extension, in a file name, is the part that follows the last
-'.', excluding version numbers and backup suffixes.
+’.’, excluding version numbers and backup suffixes.
```lisp
(f-ext "path/to/file.ext") ;; => "ext"
@@ -203,7 +206,7 @@ Return PATH relative to DIR.
### f-short `(path)`
-Return abbrev of PATH. See `abbreviate-file-name'.
+Return abbrev of PATH. See ‘abbreviate-file-name’.
Alias: `f-abbrev`
@@ -234,7 +237,7 @@ Return the canonical name of PATH.
Append slash to PATH unless one already.
-Some functions, such as `call-process' requires there to be an
+Some functions, such as ‘call-process’ requires there to be an
ending slash.
```lisp
@@ -255,7 +258,7 @@ Return absolute path to PATH, with ending slash.
### f-uniquify `(paths)`
-Return unique suffixes of PATHS.
+Return unique suffixes of FILES.
This function expects no duplicate paths.
@@ -268,7 +271,7 @@ This function expects no duplicate paths.
### f-uniquify-alist `(paths)`
-Return alist mapping PATHS to unique suffixes of PATHS.
+Return alist mapping FILES to unique suffixes of FILES.
This function expects no duplicate paths.
@@ -303,7 +306,7 @@ DATA is a unibyte string. PATH is a file name to write to.
Read text with PATH, using CODING.
-CODING defaults to `utf-8'.
+CODING defaults to ‘utf-8’.
Return the decoded text as multibyte string.
@@ -328,6 +331,29 @@ Alias: `f-write`
(f-write "Hello world" 'utf-8 "path/to/file.txt")
```
+### f-append-text `(text coding path)`
+
+Append TEXT with CODING to PATH.
+
+If PATH does not exist, it is created.
+
+Alias: `f-append`
+
+```lisp
+(f-append-text "Hello world" 'utf-8 "path/to/file.txt")
+(f-append "Hello world" 'utf-8 "path/to/file.txt")
+```
+
+### f-append-bytes `(data path)`
+
+Append binary DATA to PATH.
+
+If PATH does not exist, it is created.
+
+```lisp
+(f-append-bytes "path/to/file" (unibyte-string 72 101 108 108 111 32 119 111 114 108 100))
+```
+
### f-mkdir `(&rest dirs)`
Create directories DIRS.
@@ -351,7 +377,7 @@ If FORCE is t, a directory will be deleted recursively.
### f-symlink `(source path)`
-Create a symlink to `source` from `path`.
+Create a symlink to SOURCE from PATH.
```lisp
(f-symlink "path/to/source" "path/to/link")
@@ -375,6 +401,14 @@ Copy file or directory FROM to TO.
(f-copy "path/to/dir" "other/dir")
```
+### f-copy-contents `(from to)`
+
+Copy contents in directory FROM, to directory TO.
+
+```lisp
+(f-copy-contents "path/to/dir" "path/to/other/dir")
+```
+
### f-touch `(path)`
Update PATH last modification date or create if it does not exist.
@@ -501,7 +535,8 @@ If EXT is nil or omitted, return t if PATH has any extension,
false otherwise.
The extension, in a file name, is the part that follows the last
-'.', excluding version numbers and backup suffixes.
+’.’, excluding version numbers and backup suffixes.
+
Alias: `f-ext-p`
```lisp
@@ -513,7 +548,7 @@ Alias: `f-ext-p`
### f-same? `(path-a path-b)`
-Return t if PATH-A and PATH-b are references to same file.
+Return t if PATH-A and PATH-B are references to same file.
Aliases: `f-same-p f-equal? f-equal-p`
@@ -572,11 +607,20 @@ Alias: `f-descendant-of-p`
(f-descendant-of? "/path/to" "/path/to") ;; => nil
```
+### f-hidden? `(path)`
+
+Return t if PATH is hidden, nil otherwise.
+
+```lisp
+(f-hidden? "/path/to/foo") ;; => nil
+(f-hidden? "/path/to/.foo") ;; => t
+```
+
### f-size `(path)`
Return size of PATH.
-If PATH is a file, return size of that file. If PATH is
+If PATH is a file, return size of that file. If PATH is
directory, return sum of all files in PATH.
```lisp
@@ -588,9 +632,9 @@ directory, return sum of all files in PATH.
Return the depth of PATH.
-At first, PATH is expanded with `f-expand'. Then the full path is used to
+At first, PATH is expanded with ‘f-expand’. Then the full path is used to
detect the depth.
-'/' will be zero depth, '/usr' will be one depth. And so on.
+’/’ will be zero depth, ’/usr’ will be one depth. And so on.
```lisp
(f-depth "/") ;; 0
@@ -629,7 +673,7 @@ See: `file-expand-wildcards`
Find all files and directories in PATH.
-FN - called for each found file and directory. If FN returns a thruthy
+FN - called for each found file and directory. If FN returns a thruthy
value, file or directory will be included.
RECURSIVE - Search for files and directories recursive.
@@ -642,7 +686,7 @@ RECURSIVE - Search for files and directories recursive.
### f-directories `(path &optional fn recursive)`
-Find all directories in PATH. See `f-entries`.
+Find all directories in PATH. See ‘f-entries‘.
```lisp
(f-directories "path/to/dir")
@@ -653,7 +697,7 @@ Find all directories in PATH. See `f-entries`.
### f-files `(path &optional fn recursive)`
-Find all files in PATH. See `f-entries`.
+Find all files in PATH. See ‘f-entries‘.
```lisp
(f-files "path/to/dir")
@@ -670,27 +714,12 @@ Return absolute root.
(f-root) ;; => "/"
```
-### f-up `(fn &optional dir)`
-
-Traverse up as long as FN returns nil, starting at DIR.
-
-Deprecated in favor of: [f-traverse-upwards](#f-traverse-upwards-fn-optional-path)
-
-```lisp
-(f-up
- (lambda (path)
- (f-exists? (f-expand ".git" path)))
- start-path)
-
-(f--up (f-exists? (f-expand ".git" it)) start-path) ;; same as above
-```
-
### f-traverse-upwards `(fn &optional path)`
-Traverse up as long as FN returns nil, starting at PATH.
+Traverse up as long as FN return nil, starting at PATH.
If FN returns a non-nil value, the path sent as argument to FN is
-returned. If no function callback return a non-nil value, nil is
+returned. If no function callback return a non-nil value, nil is
returned.
```lisp
@@ -718,9 +747,11 @@ Only allow PATH-OR-PATHS and decendants to be modified in BODY.
## Changelog
-### v0.18.2
+### v0.19.0
-* Added `-p` aliases of all `?` functions.
+* Remove deprecated `f-up` function, use `f-traverse-upwards` instead
+* Add `f-append-text` and `f-append-bytes`
+* Add `f-hidden?`
### v0.18.0
diff --git a/README.md.tpl b/README.md.tpl
index c494772..a5f6eea 100644
--- a/README.md.tpl
+++ b/README.md.tpl
@@ -43,6 +43,8 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-write-bytes](#f-write-bytes-data-path) `(data path)`
* [f-read-text](#f-read-text-path-optional-coding) `(path &optional coding)`
* [f-write-text](#f-write-text-text-coding-path)`(text coding path)`
+* [f-append-text](#f-append-text-text-coding-path)`(text coding path)`
+* [f-append-bytes](#f-append-data-path)`(text coding path)`
### Destructive
@@ -51,6 +53,7 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-symlink](#f-symlink-source-path) `(source path)`
* [f-move](#f-move-from-to) `(from to)`
* [f-copy](#f-copy-from-to) `(from to)`
+* [f-copy-contenst](#f-copy-contents-from-to) `(from to)`
* [f-touch](#f-touch-path) `(path)`
### Predicates
@@ -71,6 +74,7 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-child-of?](#f-child-of-path-a-path-b) `(path-a path-b)`
* [f-ancestor-of?](#f-ancestor-of-path-a-path-b) `(path-a path-b)`
* [f-descendant-of?](#f-descendant-of-path-a-path-b) `(path-a path-b)`
+* [f-hidden?](#f-hidden-path) `(path)`
### Stats
@@ -86,7 +90,6 @@ Or you can just dump `f.el` in your load path somewhere.
* [f-directories](#f-directories-path-optional-fn-recursive) `(path &optional fn recursive)`
* [f-files](#f-files-path-optional-fn-recursive) `(path &optional fn recursive)`
* [f-root](#f-root-) `()`
-* [f-up](#f-up-fn-optional-dir) `(fn &optional dir)`
* [f-traverse-upwards](#f-traverse-upwards-fn-optional-path) `(fn &optional path)`
* [f-with-sandbox](#f-with-sandbox-path-or-paths-rest-body) `(path-or-paths &rest body)`
@@ -306,6 +309,25 @@ Alias: `f-write`
(f-write "Hello world" 'utf-8 "path/to/file.txt")
```
+### f-append-text `(text coding path)`
+
+{{f-append-text}}
+
+Alias: `f-append`
+
+```lisp
+(f-append-text "Hello world" 'utf-8 "path/to/file.txt")
+(f-append "Hello world" 'utf-8 "path/to/file.txt")
+```
+
+### f-append-bytes `(data path)`
+
+{{f-append-bytes}}
+
+```lisp
+(f-append-bytes "path/to/file" (unibyte-string 72 101 108 108 111 32 119 111 114 108 100))
+```
+
### f-mkdir `(&rest dirs)`
{{f-mkdir}}
@@ -351,6 +373,14 @@ Alias: `f-write`
(f-copy "path/to/dir" "other/dir")
```
+### f-copy-contents `(from to)`
+
+{{f-copy-contents}}
+
+```lisp
+(f-copy-contents "path/to/dir" "path/to/other/dir")
+```
+
### f-touch `(path)`
{{f-touch}}
@@ -543,6 +573,15 @@ Alias: `f-descendant-of-p`
(f-descendant-of? "/path/to" "/path/to") ;; => nil
```
+### f-hidden? `(path)`
+
+{{f-hidden?}}
+
+```lisp
+(f-hidden? "/path/to/foo") ;; => nil
+(f-hidden? "/path/to/.foo") ;; => t
+```
+
### f-size `(path)`
{{f-size}}
@@ -630,21 +669,6 @@ See: `file-expand-wildcards`
(f-root) ;; => "/"
```
-### f-up `(fn &optional dir)`
-
-{{f-up}}
-
-Deprecated in favor of: [f-traverse-upwards](#f-traverse-upwards-fn-optional-path)
-
-```lisp
-(f-up
- (lambda (path)
- (f-exists? (f-expand ".git" path)))
- start-path)
-
-(f--up (f-exists? (f-expand ".git" it)) start-path) ;; same as above
-```
-
### f-traverse-upwards `(fn &optional path)`
{{f-traverse-upwards}}
@@ -674,6 +698,12 @@ Deprecated in favor of: [f-traverse-upwards](#f-traverse-upwards-fn-optional-pat
## Changelog
+### v0.19.0
+
+* Remove deprecated `f-up` function, use `f-traverse-upwards` instead
+* Add `f-append-text` and `f-append-bytes`
+* Add `f-hidden?`
+
### v0.18.0
* Add `f-swap-ext` (by @phillord)
diff --git a/f.el b/f.el
index eacc5fa..6e2a72a 100644
--- a/f.el
+++ b/f.el
@@ -127,7 +127,7 @@ The extension, in a file name, is the part that follows the last
"Return PATH but with EXT as the new extension.
EXT must not be nil or empty."
(if (s-blank? ext)
- (error "extension cannot be empty or nil.")
+ (error "Extension cannot be empty or nil")
(concat (f-no-ext path) "." ext)))
(defun f-base (path)
@@ -140,7 +140,7 @@ EXT must not be nil or empty."
(defalias 'f-abbrev 'f-short)
(defun f-short (path)
- "Return abbrev of PATH. See `abbreviate-file-name'."
+ "Return abbrev of PATH. See `abbreviate-file-name'."
(abbreviate-file-name path))
(defun f-long (path)
@@ -181,13 +181,13 @@ ending slash."
uniq-filenames-next))
(defun f-uniquify (files)
- "Return unique suffixes of PATHS.
+ "Return unique suffixes of FILES.
This function expects no duplicate paths."
(-map 'car (f--uniquify files)))
(defun f-uniquify-alist (files)
- "Return alist mapping PATHS to unique suffixes of PATHS.
+ "Return alist mapping FILES to unique suffixes of FILES.
This function expects no duplicate paths."
(-map 'cadr (f--uniquify files)))
@@ -240,6 +240,23 @@ DATA is a unibyte string. PATH is a file name to write to."
(set-buffer-multibyte nil)
(insert data)))))
+(defalias 'f-append 'f-append-text)
+(defun f-append-text (text coding path)
+ "Append TEXT with CODING to PATH.
+
+If PATH does not exist, it is created."
+ (f-append-bytes (encode-coding-string text coding) path))
+
+(defun f-append-bytes (data path)
+ "Append binary DATA to PATH.
+
+If PATH does not exist, it is created."
+ (let ((content
+ (if (f-file? path)
+ (f-read-bytes path)
+ "")))
+ (f-write-bytes (concat content data) path)))
+
;;;; Destructive
@@ -263,7 +280,7 @@ If FORCE is t, a directory will be deleted recursively."
(delete-directory path force))))
(defun f-symlink (source path)
- "Create a symlink to `source` from `path`."
+ "Create a symlink to SOURCE from PATH."
(f--destructive path (make-symbolic-link source path)))
(defun f-move (from to)
@@ -288,6 +305,15 @@ If FORCE is t, a directory will be deleted recursively."
(copy-directory from new-to)))
(copy-directory from to))))))
+(defun f-copy-contents (from to)
+ "Copy contents in directory FROM, to directory TO."
+ (unless (f-exists? to)
+ (error "Cannot copy contents to non existing directory %s" to))
+ (unless (f-dir? from)
+ (error "Cannot copy contents as %s is a file" from))
+ (--each (f-entries from)
+ (f-copy it to)))
+
(defun f-touch (path)
"Update PATH last modification date or create if it does not exist."
(f--destructive path
@@ -379,10 +405,12 @@ The extension, in a file name, is the part that follows the last
(defalias 'f-equal-p 'f-equal?)
(defun f-same? (path-a path-b)
- "Return t if PATH-A and PATH-b are references to same file."
- (equal
- (f-canonical (f-expand path-a))
- (f-canonical (f-expand path-b))))
+ "Return t if PATH-A and PATH-B are references to same file."
+ (when (and (f-exists? path-a)
+ (f-exists? path-b))
+ (equal
+ (f-canonical (f-expand path-a))
+ (f-canonical (f-expand path-b)))))
(defalias 'f-same-p 'f-same?)
@@ -416,13 +444,19 @@ The extension, in a file name, is the part that follows the last
(defalias 'f-descendant-of-p 'f-descendant-of?)
+(defun f-hidden? (path)
+ "Return t if PATH is hidden, nil otherwise."
+ (unless (f-exists? path)
+ (error "Path does not exist: %s" path))
+ (string= (substring path 0 1) "."))
+
;;;; Stats
(defun f-size (path)
"Return size of PATH.
-If PATH is a file, return size of that file. If PATH is
+If PATH is a file, return size of that file. If PATH is
directory, return sum of all files in PATH."
(if (f-directory? path)
(-sum (-map 'f-size (f-files path nil t)))
@@ -431,9 +465,9 @@ directory, return sum of all files in PATH."
(defun f-depth (path)
"Return the depth of PATH.
-At first, PATH is expanded with `f-expand'. Then the full path is used to
+At first, PATH is expanded with `f-expand'. Then the full path is used to
detect the depth.
-'/' will be zero depth, '/usr' will be one depth. And so on."
+'/' will be zero depth, '/usr' will be one depth. And so on."
(- (length (f-split (f-expand path))) 1))
@@ -489,7 +523,7 @@ detect the depth.
(defun f-entries (path &optional fn recursive)
"Find all files and directories in PATH.
-FN - called for each found file and directory. If FN returns a thruthy
+FN - called for each found file and directory. If FN returns a thruthy
value, file or directory will be included.
RECURSIVE - Search for files and directories recursive."
(let ((entries (f--collect-entries path recursive)))
@@ -505,7 +539,7 @@ RECURSIVE - Search for files and directories recursive."
,recursive))
(defun f-directories (path &optional fn recursive)
- "Find all directories in PATH. See `f-entries`."
+ "Find all directories in PATH. See `f-entries`."
(let ((directories (-select 'f-directory? (f--collect-entries path recursive))))
(if fn (-select fn directories) directories)))
@@ -519,35 +553,10 @@ RECURSIVE - Search for files and directories recursive."
,recursive))
(defun f-files (path &optional fn recursive)
- "Find all files in PATH. See `f-entries`."
+ "Find all files in PATH. See `f-entries`."
(let ((files (-select 'f-file? (f--collect-entries path recursive))))
(if fn (-select fn files) files)))
-(defmacro f--up (body &optional dir)
- "Anaphoric version of `f-up'."
- `(f-up
- (lambda (path)
- (let ((it path))
- ,body))
- ,dir))
-
-(make-obsolete 'f-up 'f-traverse-upwards "0.14.0")
-
-(defun f-up (fn &optional dir)
- "Traverse up as long as FN returns nil, starting at DIR."
- (unless dir
- (setq dir default-directory))
- (when (f-relative? dir)
- (setq dir (f-expand dir)))
- (unless (f-exists? dir)
- (error "File %s does not exist" dir))
- (let ((parent (f-parent dir)))
- (if (and parent (f-root? parent))
- parent
- (if (funcall fn dir)
- dir
- (with-no-warnings (f-up fn parent))))))
-
(defmacro f--traverse-upwards (body &optional path)
"Anaphoric version of `f-traverse-upwards'."
`(f-traverse-upwards
@@ -557,10 +566,10 @@ RECURSIVE - Search for files and directories recursive."
,path))
(defun f-traverse-upwards (fn &optional path)
- "Traverse up as long as FN returns nil, starting at PATH.
+ "Traverse up as long as FN return nil, starting at PATH.
If FN returns a non-nil value, the path sent as argument to FN is
-returned. If no function callback return a non-nil value, nil is
+returned. If no function callback return a non-nil value, nil is
returned."
(unless path
(setq path default-directory))
diff --git a/test/f-destructive-test.el b/test/f-destructive-test.el
index 8a4b113..91e6317 100644
--- a/test/f-destructive-test.el
+++ b/test/f-destructive-test.el
@@ -187,6 +187,39 @@
(should-exist "bar/file.txt" "FILE")))
+;;;; f-copy-contents
+
+(ert-deftest-async f-copy-contents-test/not-a-directory (done)
+ (with-playground
+ (f-touch "foo.txt")
+ (f-mkdir "bar")
+ (condition-case err
+ (f-copy-contents "foo.txt" "bar")
+ (error
+ (should (string= (error-message-string err) "Cannot copy contents as foo.txt is a file"))
+ (funcall done)))))
+
+(ert-deftest-async f-copy-contents-test/directory-does-not-exist (done)
+ (with-playground
+ (f-mkdir "foo")
+ (condition-case err
+ (f-copy-contents "foo" "bar")
+ (error
+ (should (string= (error-message-string err) "Cannot copy contents to non existing directory bar"))
+ (funcall done)))))
+
+(ert-deftest f-copy-contents-test/copy-directory ()
+ (with-playground
+ (f-mkdir "from")
+ (f-mkdir "from" "foo")
+ (f-touch "from/foo/bar")
+ (f-touch "from/baz")
+ (f-mkdir "to")
+ (f-copy-contents "from" "to")
+ (should-exist "to/foo/bar")
+ (should-exist "to/baz")))
+
+
;;;; f-touch
(ert-deftest f-touch-test/file-does-not-exist-relative-path ()
diff --git a/test/f-init.el b/test/f-init.el
index 72f7b66..0a41e0d 100644
--- a/test/f-init.el
+++ b/test/f-init.el
@@ -41,7 +41,9 @@
(load (expand-file-name "f" f-test/root-path) 'noerror 'nomessage)
-(require 'ert)
+(require 'ert-async)
+(unless (require 'ert nil t)
+ (require 'ert (expand-file-name "ert" f-test/vendor-path)))
(provide 'f-init)
diff --git a/test/f-io-test.el b/test/f-io-test.el
index 828ae6f..89869e2 100644
--- a/test/f-io-test.el
+++ b/test/f-io-test.el
@@ -103,6 +103,41 @@
(f-write-bytes (unibyte-string 226 152 185 32 226 152 186) "foo.txt")
(should (equal (f-read-text "foo.txt") (f-read "foo.txt")))))
+
+;;;; f-append-text
+
+(ert-deftest f-append-text/does-not-exist ()
+ (with-playground
+ (f-append-text "foo" 'utf-8 "foo.txt")
+ (should-exist "foo.txt" "foo")))
+
+(ert-deftest f-append-text/exists ()
+ (with-playground
+ (f-write "foo" 'utf-8 "foo.txt")
+ (f-append-text "bar" 'utf-8 "foo.txt")
+ (should-exist "foo.txt" "foobar")))
+
+(ert-deftest f-append/alias ()
+ (with-playground
+ (f-append "foo" 'utf-8 "foo.txt")
+ (should-exist "foo.txt" "foo")))
+
+
+;;;; f-append-bytes
+
+(ert-deftest f-append-bytes-test/does-not-exist ()
+ (with-playground
+ (let ((bytes (apply #'unibyte-string (-map #'random (-repeat 100 255)))))
+ (f-append-bytes bytes "foo.txt")
+ (should-exist "foo.txt" bytes))))
+
+(ert-deftest f-append-bytes-test/exists ()
+ (with-playground
+ (let ((bytes (apply #'unibyte-string (-map #'random (-repeat 100 255)))))
+ (f-write-bytes bytes "foo.txt")
+ (f-append-bytes bytes "foo.txt")
+ (should-exist "foo.txt" (concat bytes bytes)))))
+
(provide 'f-io-test)
;;; f-io-test.el ends here
diff --git a/test/f-misc-test.el b/test/f-misc-test.el
index cf9e38a..26b891c 100644
--- a/test/f-misc-test.el
+++ b/test/f-misc-test.el
@@ -256,46 +256,8 @@
(should (equal (f-root) "/")))
-;;;; f-up/f--up
-(ert-deftest f-up-test/false ()
- (with-playground
- (should (equal (f-root) (f-up (lambda (path) nil))))))
-
-(ert-deftest f-up-test/true ()
- (with-playground
- (should (equal f-test/playground-path (f-up (lambda (path) t))))))
-
-(ert-deftest f-up-test/traverse-up ()
- (with-playground
- (f-touch "foo")
- (f-mkdir "bar" "baz")
- (should
- (equal
- f-test/playground-path
- (f-up
- (lambda (path)
- (f-file? (f-expand "foo" path)))
- (f-join "bar" "baz"))))))
-
-(ert-deftest f-up-test/non-existing-directory ()
- (with-playground
- (should-error
- (f-up 'ignore "err"))))
-
-(ert-deftest f-up-test/anaphoric ()
- (with-playground
- (f-touch "foo")
- (f-mkdir "bar" "baz")
- (should
- (equal
- (f--up (equal (f-filename it) "bar") (f-join "bar" "baz"))
- (f-expand "bar" f-test/playground-path)))))
-
-
;;;; f-traverse-upwards/f--traverse-upwards
-;; TODO: A lot of the tests here look similar. Any way to do some refactoring?
-
(ert-deftest f-traverse-upwards-test/no-start-path-specified ()
(with-playground
(f-touch "foo")
diff --git a/test/f-predicates-test.el b/test/f-predicates-test.el
index 9f0ce93..c1fcf3d 100644
--- a/test/f-predicates-test.el
+++ b/test/f-predicates-test.el
@@ -185,30 +185,78 @@
;;;; f-same?/f-equal?
-(ert-deftest f-same?/relative-equal ()
+(ert-deftest f-same?/does-not-exist ()
(with-playground
+ (should-not (f-same? "foo" "foo"))))
+
+(ert-deftest f-same?/relative-equal-file ()
+ (with-playground
+ (f-touch "foo")
+ (should (f-same? "foo" "foo"))))
+
+(ert-deftest f-same?/relative-equal-directory ()
+ (with-playground
+ (f-mkdir "foo")
(should (f-same? "foo" "foo"))))
-(ert-deftest f-same?/relative-not-equal ()
+(ert-deftest f-same?/relative-not-equal-files ()
+ (with-playground
+ (f-touch "foo")
+ (f-touch "bar")
+ (should-not (f-same? "foo" "bar"))))
+
+(ert-deftest f-same?/relative-not-equal-directories ()
(with-playground
+ (f-mkdir "foo")
+ (f-mkdir "bar")
(should-not (f-same? "foo" "bar"))))
-(ert-deftest f-same?/absolute-equal ()
+(ert-deftest f-same?/absolute-equal-file ()
+ (with-playground
+ (f-touch (f-expand "foo" f-test/playground-path))
+ (should (f-same? (f-expand "foo" f-test/playground-path)
+ (f-expand "foo" f-test/playground-path)))))
+
+(ert-deftest f-same?/absolute-equal-directory ()
(with-playground
+ (f-mkdir (f-expand "foo" f-test/playground-path))
(should (f-same? (f-expand "foo" f-test/playground-path)
(f-expand "foo" f-test/playground-path)))))
-(ert-deftest f-same?/absolute-not-equal ()
+(ert-deftest f-same?/absolute-not-equal-files ()
+ (with-playground
+ (f-touch (f-expand "foo" f-test/playground-path))
+ (f-touch (f-expand "bar" f-test/playground-path))
+ (should-not (f-same? (f-expand "foo" f-test/playground-path)
+ (f-expand "bar" f-test/playground-path)))))
+
+(ert-deftest f-same?/absolute-not-equal-directories ()
(with-playground
+ (f-mkdir (f-expand "foo" f-test/playground-path))
+ (f-mkdir (f-expand "bar" f-test/playground-path))
(should-not (f-same? (f-expand "foo" f-test/playground-path)
(f-expand "bar" f-test/playground-path)))))
-(ert-deftest f-same?/relative-and-absolute-equal ()
+(ert-deftest f-same?/relative-and-absolute-equal-file ()
(with-playground
+ (f-touch "foo")
+ (should (f-same? "foo" (f-expand "foo" f-test/playground-path)))))
+
+(ert-deftest f-same?/relative-and-absolute-equal-directory ()
+ (with-playground
+ (f-mkdir "foo")
(should (f-same? "foo" (f-expand "foo" f-test/playground-path)))))
+(ert-deftest f-same?/relative-and-absolute-not-equal-files ()
+ (with-playground
+ (f-touch "foo")
+ (f-touch "bar")
+ (should-not (f-same? "foo" (f-expand "bar" f-test/playground-path)))))
+
(ert-deftest f-same?/relative-and-absolute-not-equal ()
(with-playground
+ (f-mkdir "foo")
+ (f-mkdir "bar")
(should-not (f-same? "foo" (f-expand "bar" f-test/playground-path)))))
(ert-deftest f-same?/symlink ()
@@ -219,6 +267,7 @@
(ert-deftest f-equal?/alias ()
(with-playground
+ (f-touch "foo")
(should (f-equal? "foo" "foo"))))
@@ -343,6 +392,30 @@
(should-not (f-descendant-of? "foo/bar/baz/qux" "foo/bar/baz/qux"))
(should-not (f-descendant-of? (f-root) (f-root)))))
+
+;;;; f-hidden?
+
+(ert-deftest-async f-hidden?-test/does-not-exist (done)
+ (condition-case err
+ (f-hidden? "foo")
+ (error
+ (should (string= (error-message-string err) "Path does not exist: foo"))
+ (funcall done))))
+
+(ert-deftest f-hidden?-test/is-hidden ()
+ (with-playground
+ (f-touch ".foo")
+ (f-mkdir ".bar")
+ (should (f-hidden? ".foo"))
+ (should (f-hidden? ".bar"))))
+
+(ert-deftest f-hidden?-test/is-not-hidden ()
+ (with-playground
+ (f-touch "foo")
+ (f-mkdir "bar")
+ (should-not (f-hidden? "foo"))
+ (should-not (f-hidden? "bar"))))
+
(provide 'f-predicates-test)
;;; f-predicates-test.el ends here