[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 04666aacc7 1/3: Add tests for match-buffers and
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 04666aacc7 1/3: Add tests for match-buffers and buffer-match-p |
Date: |
Mon, 16 Jan 2023 09:57:25 -0500 (EST) |
branch: externals/compat
commit 04666aacc7e5d435be5359066e2bdc82b8e88eef
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add tests for match-buffers and buffer-match-p
---
compat-29.el | 4 ++--
compat-tests.el | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/compat-29.el b/compat-29.el
index f8a6630f95..86ea558490 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -189,7 +189,7 @@ signalled. If NOERROR, the non-loop parts of the chain is
returned."
(push func chain))
chain))))
-(compat-defun buffer-match-p (condition buffer-or-name &optional arg) ;;
<UNTESTED>
+(compat-defun buffer-match-p (condition buffer-or-name &optional arg) ;;
<compat-tests:buffer-match-p>
"Return non-nil if BUFFER-OR-NAME matches CONDITION.
CONDITION is either:
- the symbol t, to always match,
@@ -245,7 +245,7 @@ CONDITION is either:
(throw 'match t)))))))
(funcall match (list condition))))
-(compat-defun match-buffers (condition &optional buffers arg) ;; <UNTESTED>
+(compat-defun match-buffers (condition &optional buffers arg) ;;
<compat-tests:match-buffers>
"Return a list of buffers that match CONDITION.
See `buffer-match' for details on CONDITION. By default all
buffers are checked, this can be restricted by passing an
diff --git a/compat-tests.el b/compat-tests.el
index e79cff2187..8ba281960d 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -80,6 +80,34 @@
(setq list (funcall sym list "first" 1 #'string=))
(should (eq (compat-call plist-get list "first" #'string=) 1))))
+(ert-deftest buffer-match-p ()
+ (with-current-buffer (get-buffer-create "*compat-test-buffer*")
+ (js-mode))
+ (let ((b "*compat-test-buffer*"))
+ (should (buffer-match-p t b))
+ (should-not (buffer-match-p nil b))
+ (should (buffer-match-p "compat" b))
+ (should (buffer-match-p #'always b))
+ (should-not (buffer-match-p #'ignore b))
+ (should (buffer-match-p '(derived-mode . prog-mode) b))
+ (should-not (buffer-match-p '(derived-mode . text-mode) b))
+ (should (buffer-match-p '(major-mode . js-mode) b))
+ (should-not (buffer-match-p '(major-mode . prog-mode) b))
+ (should (buffer-match-p '(not (major-mode . prog-mode)) b))
+ (should (buffer-match-p '(and (major-mode . js-mode) "compat" t) b))
+ (should (buffer-match-p '(or (major-mode . css-mode) "foo" t) b))))
+
+(ert-deftest match-buffers ()
+ (let ((b1 (get-buffer-create "*compat-buffer-js*"))
+ (b2 (get-buffer-create "*compat-buffer-css*"))
+ (b3 (get-buffer-create "*compat-buffer-text*")))
+ (with-current-buffer b1 (js-mode))
+ (with-current-buffer b2 (css-mode))
+ (with-current-buffer b3 (text-mode))
+ (should-equal (list b2 b1)
+ (match-buffers '(or (major-mode . css-mode) (major-mode .
js-mode))
+ (list b1 b2 b3)))))
+
(ert-deftest thing-at-mouse ()
(save-window-excursion
(with-temp-buffer