]> code.delx.au - gnu-emacs-elpa/blob - packages/company/test/template-tests.el
Update packages/yasnippet by subtree-merging from its github-based upstream
[gnu-emacs-elpa] / packages / company / test / template-tests.el
1 ;;; template-tests.el --- company-mode tests -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Dmitry Gutov
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 (require 'company-tests)
23 (require 'company-template)
24
25 (ert-deftest company-template-removed-after-the-last-jump ()
26 (with-temp-buffer
27 (insert "{ }")
28 (goto-char 2)
29 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
30 (save-excursion
31 (dotimes (_ 2)
32 (insert " ")
33 (company-template-add-field tpl (point) "foo")))
34 (company-call 'template-forward-field)
35 (should (= 3 (point)))
36 (company-call 'template-forward-field)
37 (should (= 7 (point)))
38 (company-call 'template-forward-field)
39 (should (= 11 (point)))
40 (should (zerop (length (overlay-get tpl 'company-template-fields))))
41 (should (null (overlay-buffer tpl))))))
42
43 (ert-deftest company-template-removed-after-input-and-jump ()
44 (with-temp-buffer
45 (insert "{ }")
46 (goto-char 2)
47 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
48 (save-excursion
49 (insert " ")
50 (company-template-add-field tpl (point) "bar"))
51 (company-call 'template-move-to-first tpl)
52 (should (= 3 (point)))
53 (dolist (c (string-to-list "tee"))
54 (let ((last-command-event c))
55 (company-call 'self-insert-command 1)))
56 (should (string= "{ tee }" (buffer-string)))
57 (should (overlay-buffer tpl))
58 (company-call 'template-forward-field)
59 (should (= 7 (point)))
60 (should (null (overlay-buffer tpl))))))
61
62 (ert-deftest company-template-c-like-templatify ()
63 (with-temp-buffer
64 (let ((text "foo(int a, short b)"))
65 (insert text)
66 (company-template-c-like-templatify text)
67 (should (equal "foo(arg0, arg1)" (buffer-string)))
68 (should (looking-at "arg0"))
69 (should (equal "int a"
70 (overlay-get (company-template-field-at) 'display))))))
71
72 (ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
73 (with-temp-buffer
74 (let ((text "foo(int a, short b)!@ #1334 a"))
75 (insert text)
76 (company-template-c-like-templatify text)
77 (should (equal "foo(arg0, arg1)" (buffer-string)))
78 (should (looking-at "arg0")))))
79
80 (ert-deftest company-template-c-like-templatify-generics ()
81 (with-temp-buffer
82 (let ((text "foo<TKey, TValue>(int i, Dict<TKey, TValue>, long l)"))
83 (insert text)
84 (company-template-c-like-templatify text)
85 (should (equal "foo<arg0, arg1>(arg2, arg3, arg4)" (buffer-string)))
86 (should (looking-at "arg0"))
87 (should (equal "TKey" (overlay-get (company-template-field-at) 'display)))
88 (search-forward "arg3")
89 (forward-char -1)
90 (should (equal "Dict<TKey, TValue>"
91 (overlay-get (company-template-field-at) 'display))))))