;;; dired-tests.el --- Tests for directory-files in dired.c -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2020 Free Software Foundation, Inc. ;; Author: Arthur Miller ;; 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 . ;;; 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