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