branch: externals/hotfuzz
commit e41827ef0226de7874e60b2f6c7ceb13116cd4ee
Author: Axel Forsman <[email protected]>
Commit: Axel Forsman <[email protected]>

    Namespace tests
---
 hotfuzz.el    |  9 ++++-----
 test/tests.el | 43 +++++++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/hotfuzz.el b/hotfuzz.el
index b25c4c9a81..c4933e2a0d 100644
--- a/hotfuzz.el
+++ b/hotfuzz.el
@@ -1,6 +1,6 @@
 ;;; hotfuzz.el --- Fuzzy completion style  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2021 Axel Forsman
+;; Copyright (C) Axel Forsman
 
 ;; Author: Axel Forsman <[email protected]>
 ;; Version: 0.1
@@ -27,7 +27,7 @@
 (require 'hotfuzz-module nil t)
 (declare-function hotfuzz--filter-c "hotfuzz-module")
 
-(defgroup hotfuzz nil "Fuzzy completion style." :group 'minibuffer)
+(defgroup hotfuzz () "Fuzzy completion style." :group 'minibuffer)
 
 (defcustom hotfuzz-max-highlighted-completions 25
   "The number of top-ranking completions that should be highlighted.
@@ -145,8 +145,7 @@ will lead to inaccuracies."
               (cons (concat "\\`" re) completion-regexp-list))))
          (all (if (and (string= prefix "") (or (stringp (car-safe table)) 
(null table))
                        (not (or pred completion-regexp-list (string= needle 
""))))
-                  table
-                (all-completions prefix table pred))))
+                  table (all-completions prefix table pred))))
     ;; `completion-pcm--all-completions' tests completion-regexp-list
     ;; again with functional tables even though they should handle it.
     (cond
@@ -176,7 +175,7 @@ will lead to inaccuracies."
   (add-to-list 'completion-styles-alist
                '(hotfuzz completion-flex-try-completion hotfuzz-all-completions
                          "Fuzzy completion."))
-  ;; Why is the Emacs completions API so cursed?
+  ;; Why is the Emacs completion API so cursed?
   (put 'hotfuzz 'completion--adjust-metadata #'hotfuzz--adjust-metadata))
 
 (provide 'hotfuzz)
diff --git a/test/tests.el b/test/tests.el
index b56eccc649..8c19eda650 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -5,35 +5,35 @@
 
 ;;; Validation of costs of preferable traits, all else being equal
 
-(ert-deftest shorter-match-cost-test ()
+(ert-deftest hotfuzz-shorter-match-cost-test ()
   "Shorter matches should be given lower costs than longer ones."
   (should (< (hotfuzz--cost "b" "abc") (hotfuzz--cost "b" "abcd"))))
 
-(ert-deftest bos-match-cost-test ()
+(ert-deftest hotfuzz-bos-match-cost-test ()
   "Matches at the beginning are preferred."
   (should (< (hotfuzz--cost "a" "ab") (hotfuzz--cost "a" "ba"))))
 
-(ert-deftest substring-match-cost-test ()
+(ert-deftest hotfuzz-substring-match-cost-test ()
   "A substring match means fewer gaps and lower cost."
   (should (< (hotfuzz--cost "ab" "abcd") (hotfuzz--cost "ab" "acbd"))))
 
-(ert-deftest camelcase-match-cost-test ()
+(ert-deftest hotfuzz-camelcase-match-cost-test ()
   (should (< (hotfuzz--cost "ac" "AbCd") (hotfuzz--cost "ac" "abcd"))))
 
-(ert-deftest special-match-cost-test ()
+(ert-deftest hotfuzz-special-match-cost-test ()
   (should (<= (hotfuzz--cost "x" "/x")
               (hotfuzz--cost "x" "-x")
               (hotfuzz--cost "x" " x")
               (hotfuzz--cost "x" ".x")
               (hotfuzz--cost "x" "yx"))))
 
-(ert-deftest tighter-match-cost-test ()
+(ert-deftest hotfuzz-tighter-match-cost-test ()
   "Test that matches spanning fewer characters are better."
   (should (< (hotfuzz--cost "ab" "xaxbxx") (hotfuzz--cost "ab" "xaxxbx"))))
 
 ;;; Highlighting tests
 
-(ert-deftest highlight-optimal-test ()
+(ert-deftest hotfuzz-highlight-optimal-test ()
   "Test that the algorithm is non-greedy."
   (should (ert-equal-including-properties
            (hotfuzz-highlight "ab" "xaxbxabxaxbx")
@@ -41,7 +41,7 @@
 
 ;;; Filtering tests
 
-(ert-deftest case-sensitivity-test ()
+(ert-deftest hotfuzz-case-sensitivity-test ()
   (let ((xs '("aa" "aA " "Aa  " "AA   ")))
     (let ((completion-ignore-case nil))
       (should (equal (hotfuzz-all-completions "a" xs) '("aa" "aA " "Aa  ")))
@@ -50,7 +50,7 @@
       (should (equal (hotfuzz-all-completions "a" xs) xs))
       (should (equal (hotfuzz-all-completions "A" xs) xs)))))
 
-(ert-deftest long-candidates-test ()
+(ert-deftest hotfuzz-long-candidates-test ()
   (let ((a (make-string 4096 ?x))
         (b (concat (make-string 2047 ?y) "x" (make-string 2048 ?y))))
     ;; Too long candidates should still be filtered with matches
@@ -58,7 +58,7 @@
     (should (equal (hotfuzz-all-completions "x" (list (make-string 4096 ?y) b 
a "x"))
                    (list "x" b a)))))
 
-(ert-deftest filter-long-needle-test ()
+(ert-deftest hotfuzz-filter-long-needle-test ()
   (let* ((needle (make-string (1+ hotfuzz--max-needle-len) ?x))
          (a (concat needle "y")))
     ;; With a too long search string candidates should only be
@@ -66,24 +66,23 @@
     (should (equal (hotfuzz-all-completions needle (list a "y" needle))
                    (list a needle)))))
 
-(ert-deftest all-completions-test ()
+(ert-deftest hotfuzz-all-completions-test ()
   (let* ((completion-styles '(hotfuzz))
          (s "fb")
          (table '("foobar" "fxxx" "foo-baz" "" "fb"))
-         (meta (completion-metadata s table nil))
-         (candidates (completion-all-completions s table nil (length s) meta))
-         (sort-fn (alist-get 'display-sort-function meta))
-         (last (last candidates)))
-    (when (numberp (cdr last)) (setcdr last nil))
-    (when sort-fn (setq candidates (funcall sort-fn candidates)))
+         (md (completion-metadata s table nil))
+         (all (completion-all-completions s table nil (length s) md))
+         (sort-fn (completion-metadata-get md 'display-sort-function)))
+    (setcdr (last all) nil)
+    (when sort-fn (setq all (funcall sort-fn all)))
     ;; Completions should be eagerly fontified by default
     (should (equal-including-properties
-             candidates
+             all
              '(#("fb" 0 2 (face completions-common-part))
                #("foo-baz" 0 1 (face completions-common-part) 4 5 (face 
completions-common-part))
                #("foobar" 0 1 (face completions-common-part) 3 4 (face 
completions-common-part)))))))
 
-(ert-deftest display-sort-function-test ()
+(ert-deftest hotfuzz-display-sort-function-test ()
   "Test that empty strings apply the completion function 
`display-sort-function'."
   (cl-flet ((sorted-completions (string)
               (let* ((completion-styles '(hotfuzz))
@@ -92,11 +91,11 @@
                                      . ,(lambda (xs) (sort xs #'string<)))))
                      (all (completion-all-completions
                            string table nil (length string) md)))
-                (funcall (alist-get 'display-sort-function md) all))))
+                (funcall (completion-metadata-get md 'display-sort-function) 
all))))
     (should (equal (sorted-completions "") '("xax" "xbbx" "xx"))) ; 
Lexicographically sorted
     (should (equal (sorted-completions "xx") '("xx" "xax" "xbbx")))))
 
-(ert-deftest boundaries-test ()
+(ert-deftest hotfuzz-boundaries-test ()
   "Test completion on a single field of a filename."
   (let ((completion-styles '(hotfuzz)))
     (should
@@ -115,7 +114,7 @@
 
 (defvar completion-lazy-hilit)
 (defvar completion-lazy-hilit-fn)
-(ert-deftest lazy-hilit-test ()
+(ert-deftest hotfuzz-lazy-hilit-test ()
   "Test lazy fontification."
   (let ((completion-lazy-hilit t) completion-lazy-hilit-fn)
     (should (equal-including-properties (hotfuzz-all-completions "x" '("x")) 
'("x")))

Reply via email to