]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/company/company-tests.el
Merge commit 'f4ffe2b47cf6854ff3bc3ca1717efe1258c01547' from company
[gnu-emacs-elpa] / packages / company / company-tests.el
index 005bf3a544224e7fca03ef6c17de65c15e14545d..afd41565381dca1b2eedfbcaf09fecd00d739df3 100644 (file)
@@ -30,6 +30,9 @@
 (require 'company-keywords)
 (require 'company-clang)
 
+(defun company--column (&optional pos)
+  (car (company--col-row pos)))
+
 ;;; Core
 
 (ert-deftest company-sorted-keywords ()
         ;; FIXME: Make it 2?
         (should (eq (overlay-get ov 'company-height) company-tooltip-limit))
         (should (eq (overlay-get ov 'company-column) col))
-        (should (string= (overlay-get ov 'company-after)
+        (should (string= (overlay-get ov 'company-display)
                          "  123 \nc 45  c\nddd\n")))))))
 
 (ert-deftest company-pseudo-tooltip-edit-updates-width ()
         (let ((ov company-pseudo-tooltip-overlay))
           ;; With margins.
           (should (eq (overlay-get ov 'company-width) 8))
-          (should (string= (overlay-get ov 'company-after)
+          (should (string= (overlay-get ov 'company-display)
                            " 123(4) \n 45     \n")))))))
 
 (ert-deftest company-pseudo-tooltip-show-with-annotations-right-aligned ()
         (let ((ov company-pseudo-tooltip-overlay))
           ;; With margins.
           (should (eq (overlay-get ov 'company-width) 13))
-          (should (string= (overlay-get ov 'company-after)
+          (should (string= (overlay-get ov 'company-display)
                            " 123     (4) \n 45          \n 67 (891011) \n")))))))
 
 (ert-deftest company-create-lines-shows-numbers ()
                            (format " %s " (make-string (- ww 2) ?4)))
                      (company--create-lines 0 999))))))
 
+(ert-deftest company-create-lines-truncates-common-part ()
+  (let* ((ww (company--window-width))
+         (company-candidates-length 2)
+         (company-tooltip-margin 1)
+         (company-backend #'ignore))
+    (let* ((company-common (make-string (- ww 3) ?1))
+           (company-candidates `(,(concat company-common "2")
+                                 ,(concat company-common "3"))))
+      (should (equal (list (format " %s2 " (make-string (- ww 3) ?1))
+                           (format " %s3 " (make-string (- ww 3) ?1)))
+                     (company--create-lines 0 999))))
+    (let* ((company-common (make-string (- ww 2) ?1))
+           (company-candidates `(,(concat company-common "2")
+                                 ,(concat company-common "3"))))
+      (should (equal (list (format " %s " company-common)
+                           (format " %s " company-common))
+                     (company--create-lines 0 999))))
+    (let* ((company-common (make-string ww ?1))
+           (company-candidates `(,(concat company-common "2")
+                                 ,(concat company-common "3")))
+           (res (company--create-lines 0 999)))
+      (should (equal (list (format " %s " (make-string (- ww 2) ?1))
+                           (format " %s " (make-string (- ww 2) ?1)))
+                     res))
+      (should (eq 'company-tooltip-common-selection
+                    (get-text-property (- ww 2) 'face
+                                       (car res))))
+      (should (eq 'company-tooltip-selection
+                  (get-text-property (1- ww) 'face
+                                     (car res))))
+
+)))
+
 (ert-deftest company-column-with-composition ()
+  :tags '(interactive)
   (with-temp-buffer
-    (insert "lambda ()")
-    (compose-region 1 (1+ (length "lambda")) "\\")
-    (should (= (company--column) 4))))
+    (save-window-excursion
+      (set-window-buffer nil (current-buffer))
+      (insert "lambda ()")
+      (compose-region 1 (1+ (length "lambda")) "\\")
+      (should (= (company--column) 4)))))
 
 (ert-deftest company-column-with-line-prefix ()
+  :tags '(interactive)
   (with-temp-buffer
-    (insert "foo")
-    (put-text-property (point-min) (point) 'line-prefix "  ")
-    (should (= (company--column) 5))))
+    (save-window-excursion
+      (set-window-buffer nil (current-buffer))
+      (insert "foo")
+      (put-text-property (point-min) (point) 'line-prefix "  ")
+      (should (= (company--column) 5)))))
 
-(ert-deftest company-column-wth-line-prefix-on-empty-line ()
+(ert-deftest company-column-with-line-prefix-on-empty-line ()
+  :tags '(interactive)
   (with-temp-buffer
-    (insert "\n")
-    (forward-char -1)
-    (put-text-property (point-min) (point-max) 'line-prefix "  ")
-    (should (= (company--column) 2))))
+    (save-window-excursion
+      (set-window-buffer nil (current-buffer))
+      (insert "\n")
+      (forward-char -1)
+      (put-text-property (point-min) (point-max) 'line-prefix "  ")
+      (should (= (company--column) 2)))))
 
 (ert-deftest company-plainify ()
   (let ((tab-width 8))
            (company-plainify (propertize "foobar" 'line-prefix "-*-"))
            "-*-foobar")))
 
+(ert-deftest company-buffer-lines-with-lines-folded ()
+  :tags '(interactive)
+  (with-temp-buffer
+    (insert (propertize "aaa\nbbb\nccc\nddd\n" 'display "aaa+\n"))
+    (insert "eee\nfff\nggg")
+    (should (equal (company-buffer-lines (point-min) (point-max))
+                   '("aaa" "eee" "fff" "ggg")))))
+
+(ert-deftest company-buffer-lines-with-multiline-display ()
+  :tags '(interactive)
+  (with-temp-buffer
+    (insert (propertize "a" 'display "bbb\nccc\ndddd\n"))
+    (insert "eee\nfff\nggg")
+    (should (equal (company-buffer-lines (point-min) (point-max))
+                   '("" "" "" "eee" "fff" "ggg")))))
+
 (ert-deftest company-modify-line ()
   (let ((str "-*-foobar"))
     (should (equal-including-properties