1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| | ;;; dired-tests.el --- Tests for directory-files in dired.c -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2020 Free Software Foundation, Inc.
;; Author: Arthur Miller <arthur.miller@live.com>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'ert)
(ert-deftest directory-files-tests ()
(let ((name (expand-file-name "directory-files-test"
(temporary-file-directory)))
;; nodots expression from dired+ by Drew A.
(nodots "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
(message name)
(when (file-directory-p name)
(delete-directory name t))
(make-directory name)
(when (file-directory-p name)
(should (= 2 (length (directory-files name))))
(should-not (directory-files name nil nodots t 1))
(dolist (file '(a b c d))
(make-empty-file (expand-file-name (symbol-name file) name)))
(should (= 6 (length (directory-files name))))
(should (equal "abcd" (string-join (directory-files name nil
nodots) "")))
(should (= 2 (length (directory-files name nil "[bc]"))))
(should (= 3 (length (directory-files name nil nodots nil 3))))
(dolist (file '(5 4 3 2 1))
(make-empty-file (expand-file-name (number-to-string file) name)))
(should (= 0 (length (directory-files name nil "[0-9]" t -1))))
(should (= 5 (length (directory-files name nil "[0-9]" t))))
(should (= 5 (length (directory-files name nil "[0-9]" t 50))))
)))
(ert-deftest directory-files-and-attributes-tests ()
(let ((name (expand-file-name "directory-files-test"
(temporary-file-directory)))
;; nodots expression from dired+ by Drew A.
(nodots "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
(message name)
(when (file-directory-p name)
(delete-directory name t))
(make-directory name)
(when (file-directory-p name)
(should (= 2 (length (directory-files name))))
(should-not (directory-files-and-attributes name t nodots t 1))
(dolist (file '(a b c d))
(make-directory (expand-file-name (symbol-name file) name)))
(should (= 6 (length (directory-files-and-attributes name))))
(dolist (dir (directory-files-and-attributes name t nodots))
(should (file-directory-p (car dir)))
(should-not (file-regular-p (car dir))))
(should (= 2 (length
(directory-files-and-attributes name nil "[bc]"))))
(should (= 3 (length
(directory-files-and-attributes name nil nodots
nil nil 3))))
(dolist (file '(5 4 3 2 1))
(make-empty-file (expand-file-name (number-to-string file) name)))
(should (= 0 (length
(directory-files-and-attributes name nil
"[0-9]" t 1 -1))))
(should (= 5 (length
(directory-files-and-attributes name nil "[0-9]" t))))
(should (= 5 (length
(directory-files-and-attributes name nil
"[0-9]" t nil 50))))
)))
(provide 'dired-tests)
;;; dired-tests.el ends here
|