]> code.delx.au - gnu-emacs-elpa/commitdiff
Test new prefix behavior, option company-abort-manual-when-too-short
authorIngo Lohmar <i.lohmar@gmail.com>
Tue, 25 Mar 2014 21:42:09 +0000 (22:42 +0100)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 25 Mar 2014 22:29:57 +0000 (00:29 +0200)
company-tests.el

index 5a2608632ffb0009a2b3f7f8d3deef3cd3156460..e5fd2f70e4590a092d2d8f86dd5242578569668c 100644 (file)
 
 (ert-deftest company-good-prefix ()
   (let ((company-minimum-prefix-length 5)
-        company--explicit-action)
+        company--explicit-action
+        (company-selection-changed t))  ;never enough
     (should (eq t (company--good-prefix-p "!@#$%")))
     (should (eq nil (company--good-prefix-p "abcd")))
     (should (eq nil (company--good-prefix-p 'stop)))
     (should (eq t (company--good-prefix-p '("foo" . 5))))
     (should (eq nil (company--good-prefix-p '("foo" . 4))))))
 
+(ert-deftest company--manual-prefix-set-and-unset ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc" "abd")))))))
+      (company-manual-begin)
+      (should (equal "ab" company--manual-prefix))
+      (company-abort)
+      (should (null company--manual-prefix)))))
+
+(ert-deftest company-abort-manual-when-too-short ()
+  (let ((company-minimum-prefix-length 5)
+        (company-abort-manual-when-too-short t)
+        (company-selection-changed t))    ;never enough
+    (let ((company--explicit-action nil)) ;idle begin
+      (should (eq t (company--good-prefix-p "!@#$%")))
+      (should (eq nil (company--good-prefix-p "abcd")))
+      (should (eq nil (company--good-prefix-p 'stop)))
+      (should (eq t (company--good-prefix-p '("foo" . 5))))
+      (should (eq nil (company--good-prefix-p '("foo" . 4)))))
+    (let ((company--explicit-action t)
+          (company--manual-prefix "abc")) ;manual begin from this prefix
+      (should (eq t (company--good-prefix-p "!@#$")))
+      (should (eq nil (company--good-prefix-p "ab")))
+      (should (eq nil (company--good-prefix-p 'stop)))
+      (should (eq t (company--good-prefix-p '("foo" . 4))))
+      (should (eq t (company--good-prefix-p "abcd")))
+      (should (eq t (company--good-prefix-p "abcd"))))))
+
 (ert-deftest company-multi-backend-with-lambdas ()
   (let ((company-backend
          (list (lambda (command &optional arg &rest ignore)