(candidates '("c" "d")))))))
(should (equal (company-call-backend 'candidates "z") '("a" "b" "c" "d")))))
+(ert-deftest company-multi-backend-remembers-candidate-backend ()
+ (let ((company-backend
+ (list (lambda (command &optional arg &rest ignore)
+ (case command
+ (ignore-case nil)
+ (annotation "1")
+ (candidates '("a" "c"))
+ (post-completion "13")))
+ (lambda (command &optional arg &rest ignore)
+ (case command
+ (ignore-case t)
+ (annotation "2")
+ (candidates '("b" "d"))
+ (post-completion "42"))))))
+ (let ((candidates (company-calculate-candidates nil)))
+ (should (equal candidates '("a" "b" "c" "d")))
+ (should (equal t (company-call-backend 'ignore-case)))
+ (should (equal "1" (company-call-backend 'annotation (nth 0 candidates))))
+ (should (equal "2" (company-call-backend 'annotation (nth 1 candidates))))
+ (should (equal "13" (company-call-backend 'post-completion (nth 2 candidates))))
+ (should (equal "42" (company-call-backend 'post-completion (nth 3 candidates)))))))
+
+(ert-deftest company-multi-backend-handles-keyword-with ()
+ (let ((primo (lambda (command &optional arg)
+ (case command
+ (prefix "a")
+ (candidates '("abb" "abc" "abd")))))
+ (secundo (lambda (command &optional arg)
+ (case command
+ (prefix "a")
+ (candidates '("acc" "acd"))))))
+ (let ((company-backend (list 'ignore 'ignore :with secundo)))
+ (should (null (company-call-backend 'prefix))))
+ (let ((company-backend (list 'ignore primo :with secundo)))
+ (should (equal "a" (company-call-backend 'prefix)))
+ (should (equal '("abb" "abc" "abd" "acc" "acd")
+ (company-call-backend 'candidates "a"))))))
+
(ert-deftest company-begin-backend-failure-doesnt-break-company-backends ()
(with-temp-buffer
(insert "a")
(search-backward "bb")
(let ((col (company--column))
(company-candidates-length 2)
- (company-candidates '("123" "45")))
+ (company-candidates '("123" "45"))
+ (company-backend 'ignore))
(company-pseudo-tooltip-show (company--row) col 0)
(let ((ov company-pseudo-tooltip-overlay))
;; With margins.
(company-backend (lambda (action &optional arg &rest _ignore)
(when (eq action 'annotation)
(cdr (assoc arg '(("123" . "(4)")))))))
- (company-candidates '("123" "45")))
+ (company-candidates '("123" "45"))
+ company-tooltip-align-annotations)
(company-pseudo-tooltip-show-at-point (point))
(let ((ov company-pseudo-tooltip-overlay))
;; With margins.
(should (string= (overlay-get ov 'company-after)
" 123(4) \n 45 \n")))))))
+(ert-deftest company-pseudo-tooltip-show-with-annotations-right-aligned ()
+ :tags '(interactive)
+ (with-temp-buffer
+ (save-window-excursion
+ (set-window-buffer nil (current-buffer))
+ (insert " ")
+ (save-excursion (insert "\n"))
+ (let ((company-candidates-length 3)
+ (company-backend (lambda (action &optional arg &rest _ignore)
+ (when (eq action 'annotation)
+ (cdr (assoc arg '(("123" . "(4)")
+ ("67" . "(891011)")))))))
+ (company-candidates '("123" "45" "67"))
+ (company-tooltip-align-annotations t))
+ (company-pseudo-tooltip-show-at-point (point))
+ (let ((ov company-pseudo-tooltip-overlay))
+ ;; With margins.
+ (should (eq (overlay-get ov 'company-width) 13))
+ (should (string= (overlay-get ov 'company-after)
+ " 123 (4) \n 45 \n 67 (891011) \n")))))))
+
(ert-deftest company-create-lines-shows-numbers ()
(let ((company-show-numbers t)
(company-candidates '("x" "y" "z"))
- (company-candidates-length 3))
+ (company-candidates-length 3)
+ (company-backend 'ignore))
(should (equal '(" x 1 " " y 2 " " z 3 ")
(company--create-lines 0 999)))))
(let* ((ww (company--window-width))
(data `(("1" . "(123)")
("2" . nil)
- ("3" . ,(concat "(" (make-string (- ww 2) ?4) ")"))))
+ ("3" . ,(concat "(" (make-string (- ww 2) ?4) ")"))
+ (,(make-string ww ?4) . "<4>")))
(company-candidates (mapcar #'car data))
- (company-candidates-length 3)
+ (company-candidates-length 4)
(company-tooltip-margin 1)
(company-backend (lambda (cmd &optional arg)
(when (eq cmd 'annotation)
- (cdr (assoc arg data))))))
+ (cdr (assoc arg data)))))
+ company-tooltip-align-annotations)
(should (equal (list (format " 1(123)%s " (company-space-string (- ww 8)))
(format " 2%s " (company-space-string (- ww 3)))
- (format " 3(444%s " (make-string (- ww 7) ?4)))
- (company--create-lines 0 999)))))
+ (format " 3(444%s " (make-string (- ww 7) ?4))
+ (format " %s " (make-string (- ww 2) ?4)))
+ (company--create-lines 0 999)))
+ (let ((company-tooltip-align-annotations t))
+ (should (equal (list (format " 1%s(123) " (company-space-string (- ww 8)))
+ (format " 2%s " (company-space-string (- ww 3)))
+ (format " 3 (444%s " (make-string (- ww 8) ?4))
+ (format " %s " (make-string (- ww 2) ?4)))
+ (company--create-lines 0 999))))))
(ert-deftest company-column-with-composition ()
(with-temp-buffer