]> code.delx.au - gnu-emacs-elpa/blob - company-tests.el
Tag candidates from grouped backends
[gnu-emacs-elpa] / company-tests.el
1 ;;; company-tests.el --- company-mode tests
2
3 ;; Copyright (C) 2011, 2013-2014 Free Software Foundation, Inc.
4
5 ;; Author: Nikolaj Schumacher
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22
23 ;;; Commentary:
24 ;;
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29 (require 'ert)
30 (require 'company)
31 (require 'company-keywords)
32 (require 'company-elisp)
33 (require 'company-clang)
34
35 ;;; Core
36
37 (ert-deftest company-sorted-keywords ()
38 "Test that keywords in `company-keywords-alist' are in alphabetical order."
39 (dolist (pair company-keywords-alist)
40 (when (consp (cdr pair))
41 (let ((prev (cadr pair)))
42 (dolist (next (cddr pair))
43 (should (not (equal prev next)))
44 (should (string< prev next))
45 (setq prev next))))))
46
47 (ert-deftest company-good-prefix ()
48 (let ((company-minimum-prefix-length 5)
49 company--explicit-action)
50 (should (eq t (company--good-prefix-p "!@#$%")))
51 (should (eq nil (company--good-prefix-p "abcd")))
52 (should (eq nil (company--good-prefix-p 'stop)))
53 (should (eq t (company--good-prefix-p '("foo" . 5))))
54 (should (eq nil (company--good-prefix-p '("foo" . 4))))))
55
56 (ert-deftest company-multi-backend-with-lambdas ()
57 (let ((company-backend
58 (list (lambda (command &optional arg &rest ignore)
59 (case command
60 (prefix "z")
61 (candidates '("a" "b"))))
62 (lambda (command &optional arg &rest ignore)
63 (case command
64 (prefix "z")
65 (candidates '("c" "d")))))))
66 (should (equal (company-call-backend 'candidates "z") '("a" "b" "c" "d")))))
67
68 (ert-deftest company-multi-backend-remembers-candidate-backend ()
69 (let ((company-backend
70 (list (lambda (command &optional arg &rest ignore)
71 (case command
72 (ignore-case nil)
73 (annotation "1")
74 (candidates '("a" "c"))
75 (post-completion "13")))
76 (lambda (command &optional arg &rest ignore)
77 (case command
78 (ignore-case t)
79 (annotation "2")
80 (candidates '("b" "d"))
81 (post-completion "42"))))))
82 (let ((candidates (company-calculate-candidates nil)))
83 (should (equal candidates '("a" "b" "c" "d")))
84 (should (equal t (company-call-backend 'ignore-case)))
85 (should (equal "1" (company-call-backend 'annotation (nth 0 candidates))))
86 (should (equal "2" (company-call-backend 'annotation (nth 1 candidates))))
87 (should (equal "13" (company-call-backend 'post-completion (nth 2 candidates))))
88 (should (equal "42" (company-call-backend 'post-completion (nth 3 candidates)))))))
89
90 (ert-deftest company-begin-backend-failure-doesnt-break-company-backends ()
91 (with-temp-buffer
92 (insert "a")
93 (company-mode)
94 (should-error
95 (company-begin-backend (lambda (command &rest ignore))))
96 (let (company-frontends
97 (company-backends
98 (list (lambda (command &optional arg)
99 (case command
100 (prefix "a")
101 (candidates '("a" "ab" "ac")))))))
102 (let (this-command)
103 (company-call 'complete))
104 (should (eq 3 company-candidates-length)))))
105
106 (ert-deftest company-require-match-explicit ()
107 (with-temp-buffer
108 (insert "ab")
109 (company-mode)
110 (let (company-frontends
111 (company-require-match 'company-explicit-action-p)
112 (company-backends
113 (list (lambda (command &optional arg)
114 (case command
115 (prefix (buffer-substring (point-min) (point)))
116 (candidates '("abc" "abd")))))))
117 (let (this-command)
118 (company-complete))
119 (let ((last-command-event ?e))
120 (company-call 'self-insert-command 1))
121 (should (eq 2 company-candidates-length))
122 (should (eq 3 (point))))))
123
124 (ert-deftest company-dont-require-match-when-idle ()
125 (with-temp-buffer
126 (insert "ab")
127 (company-mode)
128 (let (company-frontends
129 (company-require-match 'company-explicit-action-p)
130 (company-backends
131 (list (lambda (command &optional arg)
132 (case command
133 (prefix (buffer-substring (point-min) (point)))
134 (candidates '("abc" "abd")))))))
135 (company-idle-begin (current-buffer) (selected-window)
136 (buffer-chars-modified-tick) (point))
137 (let ((last-command-event ?e))
138 (company-call 'self-insert-command 1))
139 (should (eq nil company-candidates-length))
140 (should (eq 4 (point))))))
141
142 (ert-deftest company-should-complete-whitelist ()
143 (with-temp-buffer
144 (insert "ab")
145 (company-mode)
146 (let (company-frontends
147 company-begin-commands
148 (company-backends
149 (list (lambda (command &optional arg)
150 (case command
151 (prefix (buffer-substring (point-min) (point)))
152 (candidates '("abc" "abd")))))))
153 (let ((company-continue-commands nil))
154 (let (this-command)
155 (company-complete))
156 (company-call 'backward-delete-char 1)
157 (should (null company-candidates-length)))
158 (let ((company-continue-commands '(backward-delete-char)))
159 (let (this-command)
160 (company-complete))
161 (company-call 'backward-delete-char 1)
162 (should (eq 2 company-candidates-length))))))
163
164 (ert-deftest company-should-complete-blacklist ()
165 (with-temp-buffer
166 (insert "ab")
167 (company-mode)
168 (let (company-frontends
169 company-begin-commands
170 (company-backends
171 (list (lambda (command &optional arg)
172 (case command
173 (prefix (buffer-substring (point-min) (point)))
174 (candidates '("abc" "abd")))))))
175 (let ((company-continue-commands '(not backward-delete-char)))
176 (let (this-command)
177 (company-complete))
178 (company-call 'backward-delete-char 1)
179 (should (null company-candidates-length)))
180 (let ((company-continue-commands '(not backward-delete-char-untabify)))
181 (let (this-command)
182 (company-complete))
183 (company-call 'backward-delete-char 1)
184 (should (eq 2 company-candidates-length))))))
185
186 (ert-deftest company-auto-complete-explicit ()
187 (with-temp-buffer
188 (insert "ab")
189 (company-mode)
190 (let (company-frontends
191 (company-auto-complete 'company-explicit-action-p)
192 (company-auto-complete-chars '(? ))
193 (company-backends
194 (list (lambda (command &optional arg)
195 (case command
196 (prefix (buffer-substring (point-min) (point)))
197 (candidates '("abcd" "abef")))))))
198 (let (this-command)
199 (company-complete))
200 (let ((last-command-event ? ))
201 (company-call 'self-insert-command 1))
202 (should (string= "abcd " (buffer-string))))))
203
204 (ert-deftest company-no-auto-complete-when-idle ()
205 (with-temp-buffer
206 (insert "ab")
207 (company-mode)
208 (let (company-frontends
209 (company-auto-complete 'company-explicit-action-p)
210 (company-auto-complete-chars '(? ))
211 (company-backends
212 (list (lambda (command &optional arg)
213 (case command
214 (prefix (buffer-substring (point-min) (point)))
215 (candidates '("abcd" "abef")))))))
216 (company-idle-begin (current-buffer) (selected-window)
217 (buffer-chars-modified-tick) (point))
218 (let ((last-command-event ? ))
219 (company-call 'self-insert-command 1))
220 (should (string= "ab " (buffer-string))))))
221
222 (ert-deftest company-clears-explicit-action-when-no-matches ()
223 (with-temp-buffer
224 (company-mode)
225 (let (company-frontends
226 company-backends)
227 (company-call 'manual-begin) ;; fails
228 (should (null company-candidates))
229 (should (null (company-explicit-action-p))))))
230
231 (ert-deftest company-ignore-case-replaces-prefix ()
232 (with-temp-buffer
233 (company-mode)
234 (let (company-frontends
235 company-end-of-buffer-workaround
236 (company-backends
237 (list (lambda (command &optional arg)
238 (case command
239 (prefix (buffer-substring (point-min) (point)))
240 (candidates '("abcd" "abef"))
241 (ignore-case t))))))
242 (insert "A")
243 (let (this-command)
244 (company-complete))
245 (should (string= "ab" (buffer-string)))
246 (delete-char -2)
247 (insert "A") ; hack, to keep it in one test
248 (company-complete-selection)
249 (should (string= "abcd" (buffer-string))))))
250
251 (ert-deftest company-ignore-case-with-keep-prefix ()
252 (with-temp-buffer
253 (insert "AB")
254 (company-mode)
255 (let (company-frontends
256 (company-backends
257 (list (lambda (command &optional arg)
258 (case command
259 (prefix (buffer-substring (point-min) (point)))
260 (candidates '("abcd" "abef"))
261 (ignore-case 'keep-prefix))))))
262 (let (this-command)
263 (company-complete))
264 (company-complete-selection)
265 (should (string= "ABcd" (buffer-string))))))
266
267 (ert-deftest company-non-prefix-completion ()
268 (with-temp-buffer
269 (insert "tc")
270 (company-mode)
271 (let (company-frontends
272 company-end-of-buffer-workaround
273 (company-backends
274 (list (lambda (command &optional arg)
275 (case command
276 (prefix (buffer-substring (point-min) (point)))
277 (candidates '("tea-cup" "teal-color")))))))
278 (let (this-command)
279 (company-complete))
280 (should (string= "tc" (buffer-string)))
281 (company-complete-selection)
282 (should (string= "tea-cup" (buffer-string))))))
283
284 (ert-deftest company-pseudo-tooltip-does-not-get-displaced ()
285 :tags '(interactive)
286 (with-temp-buffer
287 (save-window-excursion
288 (set-window-buffer nil (current-buffer))
289 (save-excursion (insert " ff"))
290 (company-mode)
291 (let ((company-frontends '(company-pseudo-tooltip-frontend))
292 (company-begin-commands '(self-insert-command))
293 (company-backends
294 (list (lambda (c &optional arg)
295 (case c (prefix "") (candidates '("a" "b" "c")))))))
296 (let (this-command)
297 (company-call 'complete))
298 (company-call 'open-line 1)
299 (should (eq 2 (overlay-start company-pseudo-tooltip-overlay)))))))
300
301 (ert-deftest company-pseudo-tooltip-show ()
302 :tags '(interactive)
303 (with-temp-buffer
304 (save-window-excursion
305 (set-window-buffer nil (current-buffer))
306 (insert "aaaa\n bb\nccccccc\nddd")
307 (search-backward "bb")
308 (let ((col (company--column))
309 (company-candidates-length 2)
310 (company-candidates '("123" "45"))
311 (company-backend 'ignore))
312 (company-pseudo-tooltip-show (company--row) col 0)
313 (let ((ov company-pseudo-tooltip-overlay))
314 ;; With margins.
315 (should (eq (overlay-get ov 'company-width) 5))
316 ;; FIXME: Make it 2?
317 (should (eq (overlay-get ov 'company-height) company-tooltip-limit))
318 (should (eq (overlay-get ov 'company-column) col))
319 (should (string= (overlay-get ov 'company-after)
320 " 123 \nc 45 c\nddd\n")))))))
321
322 (ert-deftest company-preview-show-with-annotations ()
323 :tags '(interactive)
324 (with-temp-buffer
325 (save-window-excursion
326 (set-window-buffer nil (current-buffer))
327 (save-excursion (insert "\n"))
328 (let ((company-candidates-length 1)
329 (company-candidates '("123")))
330 (company-preview-show-at-point (point))
331 (let ((ov company-preview-overlay))
332 (should (string= (overlay-get ov 'display) "123\n")))))))
333
334 (ert-deftest company-pseudo-tooltip-show-with-annotations ()
335 :tags '(interactive)
336 (with-temp-buffer
337 (save-window-excursion
338 (set-window-buffer nil (current-buffer))
339 (insert " ")
340 (save-excursion (insert "\n"))
341 (let ((company-candidates-length 2)
342 (company-backend (lambda (action &optional arg &rest _ignore)
343 (when (eq action 'annotation)
344 (cdr (assoc arg '(("123" . "(4)")))))))
345 (company-candidates '("123" "45"))
346 company-tooltip-align-annotations)
347 (company-pseudo-tooltip-show-at-point (point))
348 (let ((ov company-pseudo-tooltip-overlay))
349 ;; With margins.
350 (should (eq (overlay-get ov 'company-width) 8))
351 (should (string= (overlay-get ov 'company-after)
352 " 123(4) \n 45 \n")))))))
353
354 (ert-deftest company-pseudo-tooltip-show-with-annotations-right-aligned ()
355 :tags '(interactive)
356 (with-temp-buffer
357 (save-window-excursion
358 (set-window-buffer nil (current-buffer))
359 (insert " ")
360 (save-excursion (insert "\n"))
361 (let ((company-candidates-length 3)
362 (company-backend (lambda (action &optional arg &rest _ignore)
363 (when (eq action 'annotation)
364 (cdr (assoc arg '(("123" . "(4)")
365 ("67" . "(891011)")))))))
366 (company-candidates '("123" "45" "67"))
367 (company-tooltip-align-annotations t))
368 (company-pseudo-tooltip-show-at-point (point))
369 (let ((ov company-pseudo-tooltip-overlay))
370 ;; With margins.
371 (should (eq (overlay-get ov 'company-width) 13))
372 (should (string= (overlay-get ov 'company-after)
373 " 123 (4) \n 45 \n 67 (891011) \n")))))))
374
375 (ert-deftest company-create-lines-shows-numbers ()
376 (let ((company-show-numbers t)
377 (company-candidates '("x" "y" "z"))
378 (company-candidates-length 3)
379 (company-backend 'ignore))
380 (should (equal '(" x 1 " " y 2 " " z 3 ")
381 (company--create-lines 0 999)))))
382
383 (ert-deftest company-create-lines-truncates-annotations ()
384 (let* ((ww (company--window-width))
385 (data `(("1" . "(123)")
386 ("2" . nil)
387 ("3" . ,(concat "(" (make-string (- ww 2) ?4) ")"))
388 (,(make-string ww ?4) . "<4>")))
389 (company-candidates (mapcar #'car data))
390 (company-candidates-length 4)
391 (company-tooltip-margin 1)
392 (company-backend (lambda (cmd &optional arg)
393 (when (eq cmd 'annotation)
394 (cdr (assoc arg data)))))
395 company-tooltip-align-annotations)
396 (should (equal (list (format " 1(123)%s " (company-space-string (- ww 8)))
397 (format " 2%s " (company-space-string (- ww 3)))
398 (format " 3(444%s " (make-string (- ww 7) ?4))
399 (format " %s " (make-string (- ww 2) ?4)))
400 (company--create-lines 0 999)))
401 (let ((company-tooltip-align-annotations t))
402 (should (equal (list (format " 1%s(123) " (company-space-string (- ww 8)))
403 (format " 2%s " (company-space-string (- ww 3)))
404 (format " 3 (444%s " (make-string (- ww 8) ?4))
405 (format " %s " (make-string (- ww 2) ?4)))
406 (company--create-lines 0 999))))))
407
408 (ert-deftest company-column-with-composition ()
409 (with-temp-buffer
410 (insert "lambda ()")
411 (compose-region 1 (1+ (length "lambda")) "\\")
412 (should (= (company--column) 4))))
413
414 (ert-deftest company-column-with-line-prefix ()
415 (with-temp-buffer
416 (insert "foo")
417 (put-text-property (point-min) (point) 'line-prefix " ")
418 (should (= (company--column) 5))))
419
420 (ert-deftest company-column-wth-line-prefix-on-empty-line ()
421 (with-temp-buffer
422 (insert "\n")
423 (forward-char -1)
424 (put-text-property (point-min) (point-max) 'line-prefix " ")
425 (should (= (company--column) 2))))
426
427 (ert-deftest company-plainify ()
428 (let ((tab-width 8))
429 (should (equal-including-properties
430 (company-plainify "\tabc\td\t")
431 (concat " "
432 "abc "
433 "d "))))
434 (should (equal-including-properties
435 (company-plainify (propertize "foobar" 'line-prefix "-*-"))
436 "-*-foobar")))
437
438 (ert-deftest company-modify-line ()
439 (let ((str "-*-foobar"))
440 (should (equal-including-properties
441 (company-modify-line str "zz" 4)
442 "-*-fzzbar"))
443 (should (equal-including-properties
444 (company-modify-line str "xx" 0)
445 "xx-foobar"))
446 (should (equal-including-properties
447 (company-modify-line str "zz" 10)
448 "-*-foobar zz"))))
449
450 (ert-deftest company-scrollbar-bounds ()
451 (should (equal nil (company--scrollbar-bounds 0 3 3)))
452 (should (equal nil (company--scrollbar-bounds 0 4 3)))
453 (should (equal '(0 . 0) (company--scrollbar-bounds 0 1 2)))
454 (should (equal '(1 . 1) (company--scrollbar-bounds 2 2 4)))
455 (should (equal '(2 . 3) (company--scrollbar-bounds 7 4 12)))
456 (should (equal '(1 . 2) (company--scrollbar-bounds 3 4 12)))
457 (should (equal '(1 . 3) (company--scrollbar-bounds 4 5 11))))
458
459 ;;; Template
460
461 (ert-deftest company-template-removed-after-the-last-jump ()
462 (with-temp-buffer
463 (insert "{ }")
464 (goto-char 2)
465 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
466 (save-excursion
467 (dotimes (i 2)
468 (insert " ")
469 (company-template-add-field tpl (point) "foo")))
470 (company-call 'template-forward-field)
471 (should (= 3 (point)))
472 (company-call 'template-forward-field)
473 (should (= 7 (point)))
474 (company-call 'template-forward-field)
475 (should (= 11 (point)))
476 (should (zerop (length (overlay-get tpl 'company-template-fields))))
477 (should (null (overlay-buffer tpl))))))
478
479 (ert-deftest company-template-removed-after-input-and-jump ()
480 (with-temp-buffer
481 (insert "{ }")
482 (goto-char 2)
483 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
484 (save-excursion
485 (insert " ")
486 (company-template-add-field tpl (point) "bar"))
487 (company-call 'template-move-to-first tpl)
488 (should (= 3 (point)))
489 (dolist (c (string-to-list "tee"))
490 (let ((last-command-event c))
491 (company-call 'self-insert-command 1)))
492 (should (string= "{ tee }" (buffer-string)))
493 (should (overlay-buffer tpl))
494 (company-call 'template-forward-field)
495 (should (= 7 (point)))
496 (should (null (overlay-buffer tpl))))))
497
498 (defun company-call (name &rest args)
499 (let* ((maybe (intern (format "company-%s" name)))
500 (command (if (fboundp maybe) maybe name)))
501 (let ((this-command command))
502 (run-hooks 'pre-command-hook))
503 (apply command args)
504 (let ((this-command command))
505 (run-hooks 'post-command-hook))))
506
507 (ert-deftest company-template-c-like-templatify ()
508 (with-temp-buffer
509 (let ((text "foo(int a, short b)"))
510 (insert text)
511 (company-template-c-like-templatify text)
512 (should (equal "foo(arg0, arg1)" (buffer-string)))
513 (should (looking-at "arg0"))
514 (should (equal "int a"
515 (overlay-get (company-template-field-at) 'display))))))
516
517 (ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
518 (with-temp-buffer
519 (let ((text "foo(int a, short b)!@ #1334 a"))
520 (insert text)
521 (company-template-c-like-templatify text)
522 (should (equal "foo(arg0, arg1)" (buffer-string)))
523 (should (looking-at "arg0")))))
524
525 ;;; Elisp
526
527 (defmacro company-elisp-with-buffer (contents &rest body)
528 (declare (indent 0))
529 `(with-temp-buffer
530 (insert ,contents)
531 (setq major-mode 'emacs-lisp-mode)
532 (re-search-backward "|")
533 (replace-match "")
534 (let ((company-elisp-detect-function-context t))
535 ,@body)))
536
537 (ert-deftest company-elisp-candidates-predicate ()
538 (company-elisp-with-buffer
539 "(foo ba|)"
540 (should (eq (company-elisp--candidates-predicate "ba")
541 'boundp))
542 (should (eq (let (company-elisp-detect-function-context)
543 (company-elisp--candidates-predicate "ba"))
544 'company-elisp--predicate)))
545 (company-elisp-with-buffer
546 "(foo| )"
547 (should (eq (company-elisp--candidates-predicate "foo")
548 'fboundp))
549 (should (eq (let (company-elisp-detect-function-context)
550 (company-elisp--candidates-predicate "foo"))
551 'company-elisp--predicate)))
552 (company-elisp-with-buffer
553 "(foo 'b|)"
554 (should (eq (company-elisp--candidates-predicate "b")
555 'company-elisp--predicate))))
556
557 (ert-deftest company-elisp-candidates-predicate-in-docstring ()
558 (company-elisp-with-buffer
559 "(def foo () \"Doo be doo `ide|"
560 (should (eq 'company-elisp--predicate
561 (company-elisp--candidates-predicate "ide")))))
562
563 ;; This one's also an integration test.
564 (ert-deftest company-elisp-candidates-recognizes-binding-form ()
565 (let ((company-elisp-detect-function-context t)
566 (obarray [when what whelp])
567 (what 1)
568 (whelp 2)
569 (wisp 3))
570 (company-elisp-with-buffer
571 "(let ((foo 7) (wh| )))"
572 (should (equal '("what" "whelp")
573 (company-elisp-candidates "wh"))))
574 (company-elisp-with-buffer
575 "(cond ((null nil) (wh| )))"
576 (should (equal '("when")
577 (company-elisp-candidates "wh"))))))
578
579 (ert-deftest company-elisp-candidates-predicate-binding-without-value ()
580 (loop for (text prefix predicate) in '(("(let (foo|" "foo" boundp)
581 ("(let (foo (bar|" "bar" boundp)
582 ("(let (foo) (bar|" "bar" fboundp))
583 do
584 (eval `(company-elisp-with-buffer
585 ,text
586 (should (eq ',predicate
587 (company-elisp--candidates-predicate ,prefix)))))))
588
589 (ert-deftest company-elisp-finds-vars ()
590 (let ((obarray [boo bar baz backquote])
591 (boo t)
592 (bar t)
593 (baz t))
594 (should (equal '("bar" "baz")
595 (company-elisp--globals "ba" 'boundp)))))
596
597 (ert-deftest company-elisp-finds-functions ()
598 (let ((obarray [when what whelp])
599 (what t)
600 (whelp t))
601 (should (equal '("when")
602 (company-elisp--globals "wh" 'fboundp)))))
603
604 (ert-deftest company-elisp-finds-things ()
605 (let ((obarray [when what whelp])
606 (what t)
607 (whelp t))
608 (should (equal '("what" "whelp" "when")
609 (sort (company-elisp--globals "wh" 'company-elisp--predicate)
610 'string<)))))
611
612 (ert-deftest company-elisp-locals-vars ()
613 (company-elisp-with-buffer
614 "(let ((foo 5) (bar 6))
615 (cl-labels ((borg ()))
616 (lambda (boo baz)
617 b|)))"
618 (should (equal '("bar" "baz" "boo")
619 (company-elisp--locals "b" nil)))))
620
621 (ert-deftest company-elisp-locals-single-var ()
622 (company-elisp-with-buffer
623 "(dotimes (itk 100)
624 (dolist (item items)
625 it|))"
626 (should (equal '("itk" "item")
627 (company-elisp--locals "it" nil)))))
628
629 (ert-deftest company-elisp-locals-funs ()
630 (company-elisp-with-buffer
631 "(cl-labels ((foo ())
632 (fee ()))
633 (let ((fun 4))
634 (f| )))"
635 (should (equal '("fee" "foo")
636 (sort (company-elisp--locals "f" t) 'string<)))))
637
638 (ert-deftest company-elisp-locals-skips-current-varlist ()
639 (company-elisp-with-buffer
640 "(let ((foo 1)
641 (f| )))"
642 (should (null (company-elisp--locals "f" nil)))))
643
644 (ert-deftest company-elisp-show-locals-first ()
645 (company-elisp-with-buffer
646 "(let ((floo 1)
647 (flop 2)
648 (flee 3))
649 fl|)"
650 (let ((obarray [float-pi]))
651 (let (company-elisp-show-locals-first)
652 (should (eq nil (company-elisp 'sorted))))
653 (let ((company-elisp-show-locals-first t))
654 (should (eq t (company-elisp 'sorted)))
655 (should (equal '("flee" "floo" "flop" "float-pi")
656 (company-elisp-candidates "fl")))))))
657
658 (ert-deftest company-elisp-candidates-no-duplicates ()
659 (company-elisp-with-buffer
660 "(let ((float-pi 4))
661 f|)"
662 (let ((obarray [float-pi])
663 (company-elisp-show-locals-first t))
664 (should (equal '("float-pi") (company-elisp-candidates "f"))))))
665
666 (ert-deftest company-elisp-shouldnt-complete-defun-name ()
667 (company-elisp-with-buffer
668 "(defun foob|)"
669 (should (null (company-elisp 'prefix)))))
670
671 (ert-deftest company-elisp-should-complete-def-call ()
672 (company-elisp-with-buffer
673 "(defu|"
674 (should (equal "defu" (company-elisp 'prefix)))))
675
676 (ert-deftest company-elisp-should-complete-in-defvar ()
677 ;; It will also complete the var name, at least for now.
678 (company-elisp-with-buffer
679 "(defvar abc de|"
680 (should (equal "de" (company-elisp 'prefix)))))
681
682 (ert-deftest company-elisp-shouldnt-complete-in-defun-arglist ()
683 (company-elisp-with-buffer
684 "(defsubst foobar (ba|"
685 (should (null (company-elisp 'prefix)))))
686
687 (ert-deftest company-elisp-prefix-in-defun-body ()
688 (company-elisp-with-buffer
689 "(defun foob ()|)"
690 (should (equal "" (company-elisp 'prefix)))))
691
692 ;;; Clang
693
694 (ert-deftest company-clang-objc-templatify ()
695 (with-temp-buffer
696 (let ((text "createBookWithTitle:andAuthor:"))
697 (insert text)
698 (company-clang-objc-templatify text)
699 (should (equal "createBookWithTitle:arg0 andAuthor:arg1" (buffer-string)))
700 (should (looking-at "arg0"))
701 (should (null (overlay-get (company-template-field-at) 'display))))))