emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ivy-hydra bd9945b 243/395: Fix recent regression in ivy


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra bd9945b 243/395: Fix recent regression in ivy--preselect-index
Date: Thu, 25 Feb 2021 08:32:12 -0500 (EST)

branch: externals/ivy-hydra
commit bd9945b91b64304f1ae87fe2e8eb479590e5dad8
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Fix recent regression in ivy--preselect-index
    
    * ivy.el (ivy--preselect-index): Always return an index, never nil.
    * ivy-test.el (ivy--preselect-index): New test.
---
 ivy-test.el | 18 ++++++++++++++++++
 ivy.el      | 16 ++++++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index c55ac2d..e24477b 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1538,6 +1538,24 @@ a buffer visiting a file."
            (counsel--split-command-args "counsel--format")
            '("" . "counsel--format"))))
 
+(ert-deftest ivy--preselect-index ()
+  "Test `ivy--preselect-index' behavior."
+  (should (eql (ivy--preselect-index nil ()) 0))
+  (should (eql (ivy--preselect-index nil '(nil)) 0))
+  (should (eql (ivy--preselect-index nil '(t)) 0))
+  (should (eql (ivy--preselect-index nil '(t nil)) 1))
+  (should (eql (ivy--preselect-index 0 ()) 0))
+  (should (eql (ivy--preselect-index 0 '(0)) 0))
+  (should (eql (ivy--preselect-index 0 '(1)) 0))
+  (should (eql (ivy--preselect-index 0 '(1 0)) 1))
+  (should (eql (ivy--preselect-index 0 '(a)) 0))
+  (should (eql (ivy--preselect-index 1 '(a)) 1))
+  (should (eql (ivy--preselect-index "" ()) 0))
+  (should (eql (ivy--preselect-index "" '("")) 0))
+  (should (eql (ivy--preselect-index "" '("a")) 0))
+  (should (eql (ivy--preselect-index "a+" '("a")) 0))
+  (should (eql (ivy--preselect-index "a+" '("b" "a")) 1)))
+
 (defun ivy-test-run-tests ()
   (let ((test-sets
          '(
diff --git a/ivy.el b/ivy.el
index a4d1352..bf01f20 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2746,14 +2746,14 @@ Minibuffer bindings:
 
 (defun ivy--preselect-index (preselect candidates)
   "Return the index of PRESELECT in CANDIDATES."
-  (cond ((integerp preselect)
-         (if (integerp (car candidates))
-             (cl-position preselect candidates)
-           preselect))
-        ((cl-position preselect candidates :test #'equal))
-        ((and (ivy--regex-p preselect)
-              (cl-position preselect candidates :test #'string-match-p)))
-        (t 0)))
+  (or (cond ((integerp preselect)
+             (if (integerp (car candidates))
+                 (cl-position preselect candidates)
+               preselect))
+            ((cl-position preselect candidates :test #'equal))
+            ((ivy--regex-p preselect)
+             (cl-position preselect candidates :test #'string-match-p)))
+      0))
 
 ;;* Implementation
 ;;** Regex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]