浏览代码

Fix a bug in blacklist updating and add tests for it

Ryan C. Thompson 7 年之前
父节点
当前提交
6e889e19d2
共有 2 个文件被更改,包括 35 次插入2 次删除
  1. 1 1
      ido-completing-read+.el
  2. 34 1
      tests/test-ido-completing-read+.el

+ 1 - 1
ido-completing-read+.el

@@ -1140,7 +1140,7 @@ blacklist was modified."
   (if ido-cr+-auto-update-blacklist
       (let* ((curval ido-cr+-function-blacklist)
              (defval (eval (car (get 'ido-cr+-function-blacklist 'standard-value))))
-             (new-entries (cl-set-difference curval defval :test #'equal)))
+             (new-entries (cl-set-difference defval curval :test #'equal)))
         (if new-entries
             (if (eq ido-cr+-auto-update-blacklist 'notify)
                 (display-warning 'ido-completing-read+ "There are %s new blacklist entries available. Use `M-x ido-cr+-update-blacklist' to install them. (See `ido-cr+-auto-update-blacklist' for more information.)")

+ 34 - 1
tests/test-ido-completing-read+.el

@@ -806,7 +806,40 @@ also accept a quoted list for the sake of convenience."
           (expect
            (with-simulated-input "g RET"
              (ido-completing-read+ "Prompt: " 'blacklisted-collection))
-           :to-equal "g"))))
+           :to-equal "g")))
+
+      (describe "when updating ido-cr+"
+
+        (before-each
+          (spy-on 'ido-cr+-update-blacklist :and-call-through))
+
+        (it "should update the blacklist when `ido-cr+-auto-update-blacklist' is t"
+          (assume ido-cr+-function-blacklist)
+          (let ((orig-blacklist ido-cr+-function-blacklist))
+            (customize-set-variable 'ido-cr+-auto-update-blacklist t)
+            (customize-set-variable 'ido-cr+-function-blacklist nil)
+            (ido-cr+-maybe-update-blacklist)
+            (expect 'ido-cr+-update-blacklist :to-have-been-called)
+            (expect ido-cr+-function-blacklist :to-have-same-items-as orig-blacklist)))
+        (it "should not update the blacklist when `ido-cr+-auto-update-blacklist' is nil"
+          (assume ido-cr+-function-blacklist)
+          (let ((orig-blacklist ido-cr+-function-blacklist))
+            (customize-set-variable 'ido-cr+-auto-update-blacklist nil)
+            (customize-set-variable 'ido-cr+-function-blacklist nil)
+            (ido-cr+-maybe-update-blacklist)
+            (expect 'ido-cr+-update-blacklist :not :to-have-been-called)
+            (expect ido-cr+-function-blacklist :to-have-same-items-as nil)))
+
+        (it "should notify about blacklist updates when `ido-cr+-auto-update-blacklist' is `notify'"
+          (assume ido-cr+-function-blacklist)
+          (spy-on 'display-warning)
+          (let ((orig-blacklist ido-cr+-function-blacklist))
+            (customize-set-variable 'ido-cr+-auto-update-blacklist 'notify)
+            (customize-set-variable 'ido-cr+-function-blacklist nil)
+            (ido-cr+-maybe-update-blacklist)
+            (expect 'ido-cr+-update-blacklist :not :to-have-been-called)
+            (expect 'display-warning :to-have-been-called)
+            (expect ido-cr+-function-blacklist :to-have-same-items-as nil)))))
 
     (describe "with `ido-cr+-function-whitelist'"
       (before-all