浏览代码

Allow DEF to be a symbol (or list of symbols)

Also add tests for this and other edge cases relating to unusual
inputs (i.e. obarrays, hash tables, etc.)
Ryan C. Thompson 8 年之前
父节点
当前提交
528515fea3
共有 2 个文件被更改,包括 45 次插入1 次删除
  1. 2 0
      ido-completing-read+.el
  2. 43 1
      tests/test-ido-completing-read+.el

+ 2 - 0
ido-completing-read+.el

@@ -563,6 +563,8 @@ completion for them."
             ;; Ensure DEF is a list
             (setq def (list def)))
           (when def
+            ;; Ensure DEF are strings
+            (setq def (mapcar (apply-partially #'format "%s") def))
             (setq collection (append def (cl-set-difference collection def
                                                             :test #'equal))
                   def nil))

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

@@ -397,7 +397,49 @@ passed to `all-completions' and `try-completion'."
          :to-equal
          "helicopter")
         (expect 'ido-cr+-update-dynamic-collection
-                :to-have-been-called))))
+                :to-have-been-called)))
+
+    (describe "with unusual inputs"
+      (it "should accept a COLLECTION of symbols"
+        (expect
+         (with-simulated-input "g RET"
+           (ido-completing-read+ "Prompt: " '(blue yellow green)))
+         :to-equal "green"))
+      (it "should accept a mix of strings and symbols in COLLECTION"
+        (expect
+         (with-simulated-input "g RET"
+           (ido-completing-read+ "Prompt: " '(blue "yellow" green)))
+         :to-equal "green"))
+      (it "should accept symbols in DEF"
+        (expect
+         (with-simulated-input "RET"
+           (ido-completing-read+ "Prompt: " '("blue" "yellow" "brown") nil t nil nil '(brown "green")))
+         :to-equal "brown"))
+      (it "should accept an alist COLLECTION"
+        (expect
+         (with-simulated-input "RET"
+           (ido-completing-read+
+            "Prompt: "
+            '(("blue" . blue-value)
+              ("yellow" . yellow-value)
+              (green . green-value))
+            nil nil nil nil "green"))
+         :to-equal "green"))
+      (it "should accept a hash table COLLECTION"
+        (expect
+         (with-simulated-input "RET"
+           (let ((collection (make-hash-table)))
+             (puthash "blue" 'blue-value collection)
+             (puthash "yellow" 'yellow-value collection)
+             (puthash 'green 'green-value collection)
+             (ido-completing-read+ "Prompt: " collection nil nil nil nil "green")))
+         :to-equal "green"))
+      (it "should accept an obarray COLLECTION"
+        (expect
+         (with-simulated-input "forward-char RET"
+           (ido-completing-read+ "Prompt: " obarray #'commandp
+                                 t nil nil "backward-char"))
+         :to-equal "forward-char"))))
 
   (describe "ido-ubiquitous-mode"
     ;; Set up a test command that calls `completing-read'