]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/company/test/template-tests.el
Merge commit '212c8fc3101781a2f1c55ca61772eb75a2046e87' from company
[gnu-emacs-elpa] / packages / company / test / template-tests.el
index 09548c4234e857c05098bfd81fc8584583ee5e35..da746bd72adde4a0b4a30f94b3de6ea2cba00cef 100644 (file)
 (require 'company-tests)
 (require 'company-template)
 
+(defun company-template-field-assert-text (str &optional pos)
+  (let ((field (company-template-field-at pos)))
+    (should (equal (buffer-substring-no-properties
+                    (overlay-start field)
+                    (overlay-end field))
+                   str))))
+
 (ert-deftest company-template-removed-after-the-last-jump ()
   (with-temp-buffer
     (insert "{ }")
@@ -29,8 +36,8 @@
     (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
       (save-excursion
         (dotimes (_ 2)
-          (insert " ")
-          (company-template-add-field tpl (point) "foo")))
+          (insert " foo")
+          (company-template-add-field tpl (- (point) 3) (point))))
       (company-call 'template-forward-field)
       (should (= 3 (point)))
       (company-call 'template-forward-field)
@@ -46,8 +53,8 @@
     (goto-char 2)
     (let ((tpl (company-template-declare-template (point) (1- (point-max)))))
       (save-excursion
-        (insert " ")
-        (company-template-add-field tpl (point) "bar"))
+        (insert " bar")
+        (company-template-add-field tpl (- (point) 3) (point)))
       (company-call 'template-move-to-first tpl)
       (should (= 3 (point)))
       (dolist (c (string-to-list "tee"))
     (let ((text "foo(int a, short b)"))
       (insert text)
       (company-template-c-like-templatify text)
-      (should (equal "foo(arg0, arg1)" (buffer-string)))
-      (should (looking-at "arg0"))
-      (should (equal "int a"
-                     (overlay-get (company-template-field-at) 'display))))))
+      (should (equal "foo(int a, short b)" (buffer-string)))
+      (company-template-field-assert-text "int a"))))
 
 (ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
   (with-temp-buffer
     (let ((text "foo(int a, short b)!@ #1334 a"))
       (insert text)
       (company-template-c-like-templatify text)
-      (should (equal "foo(arg0, arg1)" (buffer-string)))
-      (should (looking-at "arg0")))))
+      (should (equal "foo(int a, short b)" (buffer-string)))
+      (company-template-field-assert-text "int a"))))
 
 (ert-deftest company-template-c-like-templatify-generics ()
   (with-temp-buffer
     (let ((text "foo<TKey, TValue>(int i, Dict<TKey, TValue>, long l)"))
       (insert text)
       (company-template-c-like-templatify text)
-      (should (equal "foo<arg0, arg1>(arg2, arg3, arg4)" (buffer-string)))
-      (should (looking-at "arg0"))
-      (should (equal "TKey" (overlay-get (company-template-field-at) 'display)))
-      (search-forward "arg3")
+      (should (equal (buffer-string) text))
+      (company-template-field-assert-text "TKey")
+      (search-forward "Dict")
       (forward-char -1)
-      (should (equal "Dict<TKey, TValue>"
-                     (overlay-get (company-template-field-at) 'display))))))
+      (company-template-field-assert-text "Dict<TKey, TValue>"))))
+
+(ert-deftest company-template-c-like-func-ptr ()
+  (with-temp-buffer
+    (let ((text "foo(*)(int)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (should (equal (buffer-string) "foo(int)"))
+      (company-template-field-assert-text "int"))))
+
+(ert-deftest company-clang-objc-templatify-empty-args ()
+  (with-temp-buffer
+    (let ((text "createBookWithTitle:andAuthor:"))
+      (insert text)
+      (company-template-objc-templatify text)
+      (should (equal "createBookWithTitle:arg0 andAuthor:arg1" (buffer-string)))
+      (should (looking-at "arg0"))
+      (should (null (overlay-get (company-template-field-at) 'display))))))
+
+(ert-deftest company-template-objc-templatify ()
+  (with-temp-buffer
+    (let ((text "createBookWithTitle:(NSString) andAuthor:(id)"))
+      (insert text)
+      (company-template-objc-templatify text)
+      (should (equal (buffer-string) text))
+      (company-template-field-assert-text "(NSString)"))))