[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/bug-42149-funny-pcm-completion-scores b06aadf 1/6: Add tests for
From: |
Jo�o T�vora |
Subject: |
scratch/bug-42149-funny-pcm-completion-scores b06aadf 1/6: Add tests for bug#42149 |
Date: |
Mon, 28 Dec 2020 04:29:26 -0500 (EST) |
branch: scratch/bug-42149-funny-pcm-completion-scores
commit b06aadf7606c722cbc010e6e532db0af93e47947
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Add tests for bug#42149
* test/lisp/minibuffer-tests.el (completion--pcm-score)
(completion--pcm-first-difference-pos): New helpers.
(completion-pcm-test-1, completion-pcm-test-2)
(completion-pcm-test-3, completion-pcm-test-4)
(completion-pcm-test-5, completion-pcm-test-6)
(completion-substring-test-1, completion-substring-test-2)
(completion-substring-test-3, completion-substring-test-4)
(completion-flex-test-1, completion-flex-test-2)
(completion-flex-test-3): New tests.
Co-authored-by: Dario Gjorgjevski <dario.gjorgjevski@gmail.com>
---
test/lisp/minibuffer-tests.el | 147 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index 3273479..5988656 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -107,5 +107,152 @@
nil (length input))
(cons output (length output)))))))
+(defun completion--pcm-score (comp)
+ (get-text-property 0 'completion-score comp))
+
+(defun completion--pcm-first-difference-pos (comp)
+ (cl-loop for pos = (next-single-property-change 0 'face comp)
+ then (next-single-property-change pos 'face comp)
+ while pos
+ when (eq (get-text-property pos 'face comp)
+ 'completions-first-difference)
+ return pos))
+
+(ert-deftest completion-pcm-test-1 ()
+ ;; Point is at end, this does not match anything
+ (should (equal
+ (completion-pcm-all-completions
+ "foo" '("hello" "world" "barfoobar") nil 3)
+ nil)))
+
+(ert-deftest completion-pcm-test-2 ()
+ ;; Point is at beginning, this matches "barfoobar"
+ (should (equal
+ (car (completion-pcm-all-completions
+ "foo" '("hello" "world" "barfoobar") nil 0))
+ "barfoobar")))
+
+(ert-deftest completion-pcm-test-3 ()
+ ;; Full match!
+ (should (eql
+ (completion--pcm-score
+ (car (completion-pcm-all-completions
+ "R" '("R" "hello") nil 1)))
+ 1.0)))
+
+(ert-deftest completion-pcm-test-4 ()
+ ;; One fourth of a match and no match due to point being at the end
+ (should (eql
+ (completion--pcm-score
+ (car (completion-pcm-all-completions
+ "RO" '("RaOb") nil 1)))
+ (/ 1.0 4.0)))
+ (should (equal
+ (completion-pcm-all-completions
+ "RO" '("RaOb") nil 2)
+ nil)))
+
+(ert-deftest completion-pcm-test-5 ()
+ ;; Point is at beginning, but `completions-first-difference' is
+ ;; moved after it
+ (should (eql
+ (completion--pcm-first-difference-pos
+ (car (completion-pcm-all-completions
+ "f" '("few" "many") nil 0)))
+ 1)))
+
+(ert-deftest completion-pcm-test-6 ()
+ ;; Wildcards and delimiters work
+ (should (equal
+ (car (completion-pcm-all-completions
+ "li-pac*" '("list-packages") nil 7))
+ "list-packages"))
+ (should (equal
+ (car (completion-pcm-all-completions
+ "li-pac*" '("do-not-list-packages") nil 7))
+ nil)))
+
+(ert-deftest completion-substring-test-1 ()
+ ;; One third of a match!
+ (should (equal
+ (car (completion-substring-all-completions
+ "foo" '("hello" "world" "barfoobar") nil 3))
+ "barfoobar"))
+ (should (eql
+ (completion--pcm-score
+ (car (completion-substring-all-completions
+ "foo" '("hello" "world" "barfoobar") nil 3)))
+ (/ 1.0 3.0))))
+
+(ert-deftest completion-substring-test-2 ()
+ ;; Full match!
+ (should (eql
+ (completion--pcm-score
+ (car (completion-substring-all-completions
+ "R" '("R" "hello") nil 1)))
+ 1.0)))
+
+(ert-deftest completion-substring-test-3 ()
+ ;; Substring match
+ (should (equal
+ (car (completion-substring-all-completions
+ "custgroup" '("customize-group") nil 4))
+ "customize-group"))
+ (should (equal
+ (car (completion-substring-all-completions
+ "custgroup" '("customize-group") nil 5))
+ nil)))
+
+(ert-deftest completion-substring-test-4 ()
+ ;; `completions-first-difference' should be at the right place
+ (should (eql
+ (completion--pcm-first-difference-pos
+ (car (completion-substring-all-completions
+ "jab" '("dabjobstabby" "many") nil 1)))
+ 4))
+ (should (equal
+ (completion--pcm-first-difference-pos
+ (car (completion-substring-all-completions
+ "jab" '("dabjabstabby" "many") nil 1)))
+ 6))
+ (should (equal
+ (completion--pcm-first-difference-pos
+ (car (completion-substring-all-completions
+ "jab" '("dabjabstabby" "many") nil 3)))
+ 6)))
+
+(ert-deftest completion-flex-test-1 ()
+ ;; Fuzzy match
+ (should (equal
+ (car (completion-flex-all-completions
+ "foo" '("hello" "world" "fabrobazo") nil 3))
+ "fabrobazo")))
+
+(ert-deftest completion-flex-test-2 ()
+ ;; Full match!
+ (should (eql
+ (completion--pcm-score
+ (car (completion-flex-all-completions
+ "R" '("R" "hello") nil 1)))
+ 1.0)))
+
+(ert-deftest completion-flex-test-3 ()
+ ;; Another fuzzy match, but more of a "substring" one
+ (should (equal
+ (car (completion-flex-all-completions
+ "custgroup" '("customize-group-other-window") nil 4))
+ "customize-group-other-window"))
+ ;; `completions-first-difference' should be at the right place
+ (should (equal
+ (completion--pcm-first-difference-pos
+ (car (completion-flex-all-completions
+ "custgroup" '("customize-group-other-window") nil 4)))
+ 4))
+ (should (equal
+ (completion--pcm-first-difference-pos
+ (car (completion-flex-all-completions
+ "custgroup" '("customize-group-other-window") nil 9)))
+ 15)))
+
(provide 'completion-tests)
;;; completion-tests.el ends here
- branch scratch/bug-42149-funny-pcm-completion-scores created (now 00ff781), Jo�o T�vora, 2020/12/28
- scratch/bug-42149-funny-pcm-completion-scores 8465bf1 2/6: Make a completion test robust to custom completion styles, Jo�o T�vora, 2020/12/28
- scratch/bug-42149-funny-pcm-completion-scores b06aadf 1/6: Add tests for bug#42149,
Jo�o T�vora <=
- scratch/bug-42149-funny-pcm-completion-scores 1deade1 3/6: Robustify a helper function for test/lisp/minibuffer-tests.el, Jo�o T�vora, 2020/12/28
- scratch/bug-42149-funny-pcm-completion-scores ec02ae5 4/6: Robustify completion match scoring for incomplete/implicit patterns, Jo�o T�vora, 2020/12/28
- scratch/bug-42149-funny-pcm-completion-scores 04fdac8 5/6: Add docstring to completion-pcm--hilit-commonality, Jo�o T�vora, 2020/12/28
- scratch/bug-42149-funny-pcm-completion-scores 00ff781 6/6: Slightly simplify completion-pcm--hilit-commonality, Jo�o T�vora, 2020/12/28