1 ;;; template-tests.el --- company-mode tests -*- lexical-binding: t -*-
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Author: Dmitry Gutov
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
22 (require 'company-tests)
23 (require 'company-template)
25 (ert-deftest company-template-removed-after-the-last-jump ()
29 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
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))))))
43 (ert-deftest company-template-removed-after-input-and-jump ()
47 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
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))))))
62 (ert-deftest company-template-c-like-templatify ()
64 (let ((text "foo(int a, short b)"))
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))))))
72 (ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
74 (let ((text "foo(int a, short b)!@ #1334 a"))
76 (company-template-c-like-templatify text)
77 (should (equal "foo(arg0, arg1)" (buffer-string)))
78 (should (looking-at "arg0")))))
80 (ert-deftest company-template-c-like-templatify-generics ()
82 (let ((text "foo<TKey, TValue>(int i, Dict<TKey, TValue>, long l)"))
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")
90 (should (equal "Dict<TKey, TValue>"
91 (overlay-get (company-template-field-at) 'display))))))
93 (ert-deftest company-template-c-like-func-ptr ()
95 (let ((text "foo(*)(int)"))
97 (company-template-c-like-templatify text)
98 (should (equal "foo(arg0)" (buffer-string)))
99 (should (looking-at "arg0"))
100 (should (equal "int" (overlay-get (company-template-field-at) 'display))))))