emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 7af2b48dfc 3/3: Add missing functions subr-x fro


From: ELPA Syncer
Subject: [elpa] externals/compat 7af2b48dfc 3/3: Add missing functions subr-x from 24.4
Date: Sun, 27 Feb 2022 16:57:20 -0500 (EST)

branch: externals/compat
commit 7af2b48dfc3f903073c872d0126a370f4fa49c6c
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add missing functions subr-x from 24.4
---
 compat-24.4.el  | 44 +++++++++++++++++++++++++++++++
 compat-tests.el | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)

diff --git a/compat-24.4.el b/compat-24.4.el
index dbcbc92d1e..d598518fc8 100644
--- a/compat-24.4.el
+++ b/compat-24.4.el
@@ -186,5 +186,49 @@ Defaults to `error'."
             (funcall (eval form t)))))
     (apply oldfun feature args)))
 
+(compat-defun hash-table-keys (hash-table)
+  "Return a list of keys in HASH-TABLE."
+  (let (values)
+    (maphash
+     (lambda (k _v) (push k values))
+     hash-table)
+    values))
+
+(compat-defun hash-table-values (hash-table)
+  "Return a list of values in HASH-TABLE."
+  (let (values)
+    (maphash
+     (lambda (_k v) (push v values))
+     hash-table)
+    values))
+
+(compat-defun string-empty-p (string)
+  "Check whether STRING is empty."
+  (string= string ""))
+
+(compat-defun string-join (strings &optional separator)
+  "Join all STRINGS using SEPARATOR.
+Optional argument SEPARATOR must be a string, a vector, or a list of
+characters; nil stands for the empty string."
+  (mapconcat #'identity strings separator))
+
+(compat-defun string-blank-p (string)
+  "Check whether STRING is either empty or only whitespace.
+The following characters count as whitespace here: space, tab, newline and
+carriage return."
+  (string-match-p "\\`[ \t\n\r]*\\'" string))
+
+(compat-defun string-remove-prefix (prefix string)
+  "Remove PREFIX from STRING if present."
+  (if (string-prefix-p prefix string)
+      (substring string (length prefix))
+    string))
+
+(compat-defun string-remove-suffix (suffix string)
+  "Remove SUFFIX from STRING if present."
+  (if (string-suffix-p suffix string)
+      (substring string 0 (- (length string) (length suffix)))
+    string))
+
 (provide 'compat-24.4)
 ;;; compat-24.4.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index 6a9f7f0c9f..99d5a862b5 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1339,5 +1339,85 @@ the compatibility function."
       (compat--should 'foo (list a-map b-map) "x")
       (compat--should 'bar (list b-map a-map) "x"))))
 
+(ert-deftest compat-hash-table-keys ()
+  "Check if `compat--hash-table-keys' was implemented properly."
+  (let ((ht (make-hash-table)))
+    (compat-test hash-table-keys
+      (compat--should '() ht)
+      (puthash 1 'one ht)
+      (compat--should '(1) ht)
+      (puthash 1 'one ht)
+      (compat--should '(1) ht)
+      (remhash 1 ht)
+      (compat--should '() ht)
+      (puthash 2 'two ht)
+      (compat--should '(2) ht))))
+
+(ert-deftest compat-hash-table-values ()
+  "Check if `compat--hash-table-values' was implemented properly."
+  (let ((ht (make-hash-table)))
+    (compat-test hash-table-values
+      (compat--should '() ht)
+      (puthash 1 'one ht)
+      (compat--should '(one) ht)
+      (puthash 1 'one ht)
+      (compat--should '(one) ht)
+      (remhash 1 ht)
+      (compat--should '() ht)
+      (puthash 2 'two ht)
+      (compat--should '(two) ht))))
+
+(ert-deftest compat-string-empty-p ()
+  "Check if `compat--string-empty-p' was implemented properly."
+  (compat-test string-empty-p
+    (compat--should t "")
+    (compat--should nil " ")
+    (compat--should t (make-string 0 ?x))
+    (compat--should nil (make-string 1 ?x))))
+
+(ert-deftest compat-string-join ()
+  "Check if `compat--string-join' was implemented properly."
+  (compat-test string-join
+    (compat--should "" '(""))
+    (compat--should "" '("") " ")
+    (compat--should "a" '("a"))
+    (compat--should "a" '("a") " ")
+    (compat--should "abc" '("a" "b" "c"))
+    (compat--should "a b c" '("a" "b" "c") " ")))
+
+(ert-deftest compat-string-blank-p ()
+  "Check if `compat--string-blank-p' was implemented properly."
+  (compat-test string-blank-p
+    (compat--should 0 "")
+    (compat--should 0 " ")
+    (compat--should 0 (make-string 0 ?x))
+    (compat--should nil (make-string 1 ?x))))
+
+(ert-deftest compat-string-remove-prefix ()
+  "Check if `compat--string-remove-prefix was implemented properly."
+  (compat-test string-remove-prefix
+    (compat--should "" "" "")
+    (compat--should "a" "" "a")
+    (compat--should "" "a" "")
+    (compat--should "bc" "a" "abc")
+    (compat--should "abc" "c" "abc")
+    (compat--should "bbcc" "aa" "aabbcc")
+    (compat--should "aabbcc" "bb" "aabbcc")
+    (compat--should "aabbcc" "cc" "aabbcc")
+    (compat--should "aabbcc" "dd" "aabbcc")))
+
+(ert-deftest compat-string-remove-suffix ()
+  "Check if `compat--string-remove-suffix was implemented properly."
+  (compat-test string-remove-suffix
+    (compat--should "" "" "")
+    (compat--should "a" "" "a")
+    (compat--should "" "a" "")
+    (compat--should "abc" "a" "abc")
+    (compat--should "ab" "c" "abc")
+    (compat--should "aabbcc" "aa" "aabbcc")
+    (compat--should "aabbcc" "bb" "aabbcc")
+    (compat--should "aabb" "cc" "aabbcc")
+    (compat--should "aabbcc" "dd" "aabbcc")))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]