From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dario Gjorgjevski Newsgroups: gmane.emacs.bugs Subject: bug#42149: Substring and flex completion ignore implicit trailing =?UTF-8?Q?=E2=80=98any=E2=80=99?= Date: Thu, 13 May 2021 17:41:54 +0200 Message-ID: References: <87sgbsv7gg.fsf@gmail.com> <877dp1kfzz.fsf@gmail.com> <8735zpjz64.fsf@gmail.com> <877dk3rnoo.fsf@gnus.org> <87im3maeny.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13793"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 42149@debbugs.gnu.org, Lars Ingebrigtsen , Stefan Monnier To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 13 17:43:29 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lhDUm-0003TN-IM for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 May 2021 17:43:28 +0200 Original-Received: from localhost ([::1]:44912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhDUk-0000qx-PT for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 May 2021 11:43:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhDUM-0000qo-Mi for bug-gnu-emacs@gnu.org; Thu, 13 May 2021 11:43:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lhDUM-0001Dm-FY for bug-gnu-emacs@gnu.org; Thu, 13 May 2021 11:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lhDUM-0006mL-CI for bug-gnu-emacs@gnu.org; Thu, 13 May 2021 11:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dario Gjorgjevski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 May 2021 15:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42149 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 42149-submit@debbugs.gnu.org id=B42149.162092053025985 (code B ref 42149); Thu, 13 May 2021 15:43:02 +0000 Original-Received: (at 42149) by debbugs.gnu.org; 13 May 2021 15:42:10 +0000 Original-Received: from localhost ([127.0.0.1]:44156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhDTV-0006l3-MF for submit@debbugs.gnu.org; Thu, 13 May 2021 11:42:10 -0400 Original-Received: from mail-wr1-f51.google.com ([209.85.221.51]:41868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhDTO-0006kT-4X for 42149@debbugs.gnu.org; Thu, 13 May 2021 11:42:08 -0400 Original-Received: by mail-wr1-f51.google.com with SMTP id d11so27313436wrw.8 for <42149@debbugs.gnu.org>; Thu, 13 May 2021 08:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=+tufT/V+qLhxBckbndT8+ahPE4D+9lyo86jrzd1AOGc=; b=vhA/OtIKOsh9eOTyAGXOdVSeZDVA+dh3ulSJm86sj8POtf8eY1vwyNIPbZv7csc9ZO G1dZRYq8nI0aoB5bMijlqrWN3xFC7bekvRnJigfxwxiccxMqoFSpmN7NQxuQtOg0whQr iOHBz9+fSHrYaeVBbhHCBKz5fLkHtbXxz5iDdigwXo9bVVB0v7Sqv3DLDKH+BNhS7PA8 RNJUxl+Ere4CZSPnZ5hIinR15Ythk3o3wg07tVApGjYjl6uQxp3Qy2ynoi0vw5PjWldY pNiiuA1yluMuNyinpTYA0PaDGyW5iZ0HytGrpF0OxiFpRLQwaRcemYzVqS8N5mJKCXKG 7QlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=+tufT/V+qLhxBckbndT8+ahPE4D+9lyo86jrzd1AOGc=; b=AIuEGNlS/nhaP8JT9BKguB2NYrr78HS6TRgvA5yZIWvpLPUOPGlWebteyG2KvTTuG9 qm2xRm8zxbrNwb5604BTPwf3TXB+VnOZAnLSE/XrEoMjrTCrJjwv0pCPCQH0uh/1lQra sDdNDb7BoN1keW9RXxg7SoefOVs7m1a2MLZQueu1P8NUenaWvc1345ZqfdmkZJuFxev2 T2L1yOyoJEoZWPiR1QGS9X3F6B+TzEzKAV+bfwgwmtwvYdHAa8t9ZnKJocbWcsra+xbc Qasv0OCMW+LvmilSQzWSf09BN4SpbRxklmp2NA2mzaB7GPZSo4tJWVU6aTi880iOBu/V Okmg== X-Gm-Message-State: AOAM5336G2pTshjaQtK3AVal4SwLMdSTX4hIA1p7A0Ae4B0DMVMyPyW+ QQl405d8YiXvzR1LGAkFQEyw96AydxqXMw== X-Google-Smtp-Source: ABdhPJxNne9UFJFykdlun1O9V7rXCEc8aHK4n67x4KWWTimn344X+//+omSNd9hLH2vekp9duJoJnA== X-Received: by 2002:a5d:6811:: with SMTP id w17mr53666466wru.348.1620920516361; Thu, 13 May 2021 08:41:56 -0700 (PDT) Original-Received: from ZALANDO-31298 ([79.140.114.107]) by smtp.gmail.com with ESMTPSA id y21sm9200839wmi.15.2021.05.13.08.41.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 May 2021 08:41:55 -0700 (PDT) In-Reply-To: <87im3maeny.fsf@gmail.com> ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Thu, 13 May 2021 15:31:29 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:206449 Archived-At: --=-=-= Content-Type: text/plain Hi, > Not sure if it's merged yet, but I don't think so. I was waiting for > Dario's comments on it, they never arrived, but I'm veryq confident that > this fixes the issues reported here. Sorry, I kind of forgot about this. The bug itself was fixed by commit d199a46, it is only the test that have not been merged yet. The tests that fail are the ones related to completions-first-difference, which, we agreed should be left as it is. Therefore, those tests need to be changed. (This also applies to the scratch/bug-42149-funny-pcm-completion-scores branch.) Here is a patch with the fixed tests: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Add-tests-for-bug-42149.patch Content-Transfer-Encoding: quoted-printable Content-Description: Add tests for bug#42149 >From 215ac5b9c55670435b69fa92d6124d0c7bf9b5a3 Mon Sep 17 00:00:00 2001 From: Dario Gjorgjevski Date: Thu, 13 May 2021 17:29:13 +0200 Subject: [PATCH] Add tests for bug#42149 MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * 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: Jo=C3=A3o T=C3=A1vora --- test/lisp/minibuffer-tests.el | 143 ++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 6ab5f57eff..c3ba8f9a92 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -188,5 +188,148 @@ '("some/alpha" "base/epsilon" "base/delta")) `("epsilon" "delta" "beta" "alpha" "gamma" . 5)))) =20 +(defun completion--pcm-score (comp) + "Get `completion-score' from COMP." + (get-text-property 0 'completion-score comp)) + +(defun completion--pcm-first-difference-pos (comp) + "Get `completions-first-difference' from COMP." + (cl-loop for pos =3D (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 (null + (completion-pcm-all-completions + "foo" '("hello" "world" "barfoobar") nil 3)))) + +(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 (null + (completion-pcm-all-completions + "RO" '("RaOb") nil 2)))) + +(ert-deftest completion-pcm-test-5 () + ;; Since point is at the beginning, there is nothing that can really + ;; be typed anymore + (should (null + (completion--pcm-first-difference-pos + (car (completion-pcm-all-completions + "f" '("few" "many") nil 0)))))) + +(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 (null + (car (completion-pcm-all-completions + "li-pac*" '("do-not-list-packages") nil 7))))) + +(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 (null + (car (completion-substring-all-completions + "custgroup" '("customize-group") nil 5))))) + +(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 (null + (completion--pcm-first-difference-pos + (car (completion-substring-all-completions + "jab" '("dabjabstabby" "many") nil 1))))) + (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 'minibuffer-tests) ;;; minibuffer-tests.el ends here --=20 2.31.GIT --=-=-= Content-Type: text/plain Once the tests are merged, I suppose the scratch/bug-42149-funny-pcm-completion-scores branch can safely be deleted. Best regards, -- Dario Gjorgjevski Key fingerprint = F7C3 734D 2381 DAEB 4C6D 9CF7 744A 4F0B 4F1C 9371 $ gpg --keyserver hkps://hkps.pool.sks-keyservers.net \ --search-keys 744A4F0B4F1C9371 --=-=-=--