(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)