]> code.delx.au - gnu-emacs-elpa/blobdiff - test/core-tests.el
Revert "Remove completions without annotations when considering duplicates"
[gnu-emacs-elpa] / test / core-tests.el
index 0ff691e4ba3881cb7b376eabeccb80c742cdd6f4..666ed80e000805ced9922c2e10e88df00e337ea0 100644 (file)
       (should (eq nil company-candidates-length))
       (should (eq 4 (point))))))
 
-(ert-deftest company-dont-require-match-if-old-prefix-ended-and-was-a-match ()
+(ert-deftest company-dont-require-match-if-was-a-match-and-old-prefix-ended ()
   (with-temp-buffer
     (insert "ab")
     (company-mode)
     (let (company-frontends
-          (company-require-match 'company-explicit-action-p)
+          company-auto-complete
+          (company-require-match t)
           (company-backends
            (list (lambda (command &optional _)
                    (cl-case command
       (should (null company-candidates-length))
       (should (eq 4 (point))))))
 
+(ert-deftest company-dont-require-match-if-was-a-match-and-new-prefix-is-stop ()
+  (with-temp-buffer
+    (company-mode)
+    (insert "c")
+    (let (company-frontends
+          (company-require-match t)
+          (company-backends
+           (list (lambda (command &optional _)
+                   (cl-case command
+                     (prefix (if (> (point) 2)
+                                 'stop
+                               (buffer-substring (point-min) (point))))
+                     (candidates '("a" "b" "c")))))))
+      (let (this-command)
+        (company-complete))
+      (should (eq 3 company-candidates-length))
+      (let ((last-command-event ?e))
+        (company-call 'self-insert-command 1))
+      (should (not company-candidates)))))
+
 (ert-deftest company-should-complete-whitelist ()
   (with-temp-buffer
     (insert "ab")
       (company-complete-selection)
       (should (string= "tea-cup" (buffer-string))))))
 
+(defvar ct-sorted nil)
+
+(defun ct-equal-including-properties (list1 list2)
+  (or (and (not list1) (not list2))
+      (and (ert-equal-including-properties (car list1) (car list2))
+           (ct-equal-including-properties (cdr list1) (cdr list2)))))
+
+(ert-deftest company-strips-duplicates-returns-nil ()
+  (should (null (company--preprocess-candidates nil))))
+
+(ert-deftest company-strips-duplicates-within-groups ()
+  (let* ((kvs '(("a" . "b")
+                ("a" . nil)
+                ("a" . "b")
+                ("a" . "c")
+                ("a" . "b")
+                ("b" . "c")
+                ("b" . nil)
+                ("a" . "b")))
+         (fn (lambda (kvs)
+               (mapcar (lambda (kv) (propertize (car kv) 'ann (cdr kv)))
+                       kvs)))
+         (company-backend
+          (lambda (command &optional arg)
+            (pcase command
+              (`prefix "")
+              (`sorted ct-sorted)
+              (`duplicates t)
+              (`annotation (get-text-property 0 'ann arg)))))
+         (reference '(("a" . "b")
+                      ("a" . nil)
+                      ("a" . "c")
+                      ("b" . "c")
+                      ("b" . nil)
+                      ("a" . "b"))))
+    (let ((ct-sorted t))
+      (should (ct-equal-including-properties
+               (company--preprocess-candidates (funcall fn kvs))
+               (funcall fn reference))))
+    (should (ct-equal-including-properties
+             (company--preprocess-candidates (funcall fn kvs))
+             (funcall fn (butlast reference))))))
+
 ;;; Row and column
 
 (ert-deftest company-column-with-composition ()