all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#23357: [PATCH] Don't let `css--property-values' return duplicates
@ 2016-04-24 12:57 Simen Heggestøyl
  2016-04-24 14:51 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Simen Heggestøyl @ 2016-04-24 12:57 UTC (permalink / raw)
  To: 23357; +Cc: Stefan Monnier, Dmitry Gutov


[-- Attachment #1.1: Type: text/plain, Size: 337 bytes --]

By a recent discussion on emacs-devel I was made aware that
completion-at-point functions are themselves responsible for removing
duplicate entries in their results.

The attached patch ensures that `css--property-values' doesn't return
duplicate values as it would otherwise do sometimes, along with a
regression test for it.

-- Simen

[-- Attachment #1.2: Type: text/html, Size: 435 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-let-css-property-values-return-duplicates.patch --]
[-- Type: text/x-patch, Size: 3458 bytes --]

From 83ada4ea1fdd8329d5383301dca25839cf46c827 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sun, 24 Apr 2016 11:03:34 +0200
Subject: [PATCH] Don't let `css--property-values' return duplicates

* lisp/textmodes/css-mode.el (css--property-values): Don't return
duplicate values.

* test/lisp/textmodes/css-mode-tests.el (css-test-property-values):
Take the above into account.
(css-test-property-values-no-duplicates): Test that duplicates aren't
returned by `css--property-values'.
---
 lisp/textmodes/css-mode.el            | 15 ++++++++-------
 test/lisp/textmodes/css-mode-tests.el | 18 ++++++++++++++----
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 2a61fe3..792d482 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -792,13 +792,14 @@ css--property-values
 Completion candidates are looked up in `css-property-alist' by
 the string PROPERTY."
   (or (gethash property css--property-value-cache)
-      (seq-mapcat
-       (lambda (value)
-         (if (stringp value)
-             (list value)
-           (or (css--value-class-lookup value)
-               (css--property-values (symbol-name value)))))
-       (cdr (assoc property css-property-alist)))))
+      (seq-uniq
+       (seq-mapcat
+        (lambda (value)
+          (if (stringp value)
+              (list value)
+            (or (css--value-class-lookup value)
+                (css--property-values (symbol-name value)))))
+        (cdr (assoc property css-property-alist))))))
 
 (defun css--complete-property-value ()
   "Complete property value at point."
diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el
index 9c5953d..ee5705f 100644
--- a/test/lisp/textmodes/css-mode-tests.el
+++ b/test/lisp/textmodes/css-mode-tests.el
@@ -24,8 +24,9 @@
 
 ;;; Code:
 
-(require 'ert)
 (require 'css-mode)
+(require 'ert)
+(require 'seq)
 
 (ert-deftest css-test-property-values ()
   ;; The `float' property has a flat value list.
@@ -36,9 +37,10 @@
   ;; The `list-style' property refers to several other properties.
   (should
    (equal (sort (css--property-values "list-style") #'string-lessp)
-          (sort (append (css--property-values "list-style-type")
-                        (css--property-values "list-style-position")
-                        (css--property-values "list-style-image"))
+          (sort (seq-uniq
+                 (append (css--property-values "list-style-type")
+                         (css--property-values "list-style-position")
+                         (css--property-values "list-style-image")))
                 #'string-lessp)))
 
   ;; The `position' property is tricky because it's also the name of a
@@ -57,6 +59,14 @@
   ;; because it refers to the value class of the same name.
   (should (= (length (css--property-values "color")) 18)))
 
+(ert-deftest css-test-property-values-no-duplicates ()
+  "Test that `css--property-values' returns no duplicates."
+  ;; The `flex' property is prone to duplicate values; if they aren't
+  ;; removed, it'll contain at least two instances of `auto'.
+  (should
+   (equal (sort (css--property-values "flex") #'string-lessp)
+          '("auto" "content" "none"))))
+
 (ert-deftest css-test-value-class-lookup ()
   (should
    (equal (sort (css--value-class-lookup 'position) #'string-lessp)
-- 
2.8.0.rc3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-24 18:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-24 12:57 bug#23357: [PATCH] Don't let `css--property-values' return duplicates Simen Heggestøyl
2016-04-24 14:51 ` Stefan Monnier
2016-04-24 18:04   ` Simen Heggestøyl

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.