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 (defun company-template-field-assert-text (str &optional pos)
26 (let ((field (company-template-field-at pos)))
27 (should (equal (buffer-substring-no-properties
32 (ert-deftest company-template-removed-after-the-last-jump ()
36 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
40 (company-template-add-field tpl (- (point) 3) (point))))
41 (company-call 'template-forward-field)
42 (should (= 3 (point)))
43 (company-call 'template-forward-field)
44 (should (= 7 (point)))
45 (company-call 'template-forward-field)
46 (should (= 11 (point)))
47 (should (zerop (length (overlay-get tpl 'company-template-fields))))
48 (should (null (overlay-buffer tpl))))))
50 (ert-deftest company-template-removed-after-input-and-jump ()
54 (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
57 (company-template-add-field tpl (- (point) 3) (point)))
58 (company-call 'template-move-to-first tpl)
59 (should (= 3 (point)))
60 (dolist (c (string-to-list "tee"))
61 (let ((last-command-event c))
62 (company-call 'self-insert-command 1)))
63 (should (string= "{ tee }" (buffer-string)))
64 (should (overlay-buffer tpl))
65 (company-call 'template-forward-field)
66 (should (= 7 (point)))
67 (should (null (overlay-buffer tpl))))))
69 (ert-deftest company-template-c-like-templatify ()
71 (let ((text "foo(int a, short b)"))
73 (company-template-c-like-templatify text)
74 (should (equal "foo(int a, short b)" (buffer-string)))
75 (company-template-field-assert-text "int a"))))
77 (ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
79 (let ((text "foo(int a, short b)!@ #1334 a"))
81 (company-template-c-like-templatify text)
82 (should (equal "foo(int a, short b)" (buffer-string)))
83 (company-template-field-assert-text "int a"))))
85 (ert-deftest company-template-c-like-templatify-generics ()
87 (let ((text "foo<TKey, TValue>(int i, Dict<TKey, TValue>, long l)"))
89 (company-template-c-like-templatify text)
90 (should (equal (buffer-string) text))
91 (company-template-field-assert-text "TKey")
92 (search-forward "Dict")
94 (company-template-field-assert-text "Dict<TKey, TValue>"))))
96 (ert-deftest company-template-c-like-func-ptr ()
98 (let ((text "foo(*)(int)"))
100 (company-template-c-like-templatify text)
101 (should (equal (buffer-string) "foo(int)"))
102 (company-template-field-assert-text "int"))))