summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/ring-tests.el
diff options
context:
space:
mode:
authorAllen Li <darkfeline@felesatra.moe>2018-10-24 20:44:01 -0600
committerEli Zaretskii <eliz@gnu.org>2018-11-10 11:41:51 +0200
commit5578112e182e20661783a1fef2c779b8844cf082 (patch)
treef7ab48c6949bf6b0598ed705578a4cacae554207 /test/lisp/emacs-lisp/ring-tests.el
parent705adc237629a78c10165f9a3b3260cb56242cda (diff)
downloademacs-5578112e182e20661783a1fef2c779b8844cf082.tar.gz
emacs-5578112e182e20661783a1fef2c779b8844cf082.tar.bz2
emacs-5578112e182e20661783a1fef2c779b8844cf082.zip
Add 'ring-resize' function
* lisp/emacs-lisp/ring.el (ring-resize): New function. (Bug#32849) * doc/lispref/sequences.texi (Rings): Document new function 'ring-resize'. * etc/NEWS: Document new function 'ring-resize'. * test/lisp/emacs-lisp/ring-tests.el (ring-test-ring-resize): New tests.
Diffstat (limited to 'test/lisp/emacs-lisp/ring-tests.el')
-rw-r--r--test/lisp/emacs-lisp/ring-tests.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/ring-tests.el b/test/lisp/emacs-lisp/ring-tests.el
index 0b4e3d9a694..9fa36aa3d33 100644
--- a/test/lisp/emacs-lisp/ring-tests.el
+++ b/test/lisp/emacs-lisp/ring-tests.el
@@ -162,6 +162,43 @@
(should (= (ring-size ring) 5))
(should (equal (ring-elements ring) '(3 2 1)))))
+(ert-deftest ring-resize/grow ()
+ (let ((ring (make-ring 3)))
+ (ring-insert ring 1)
+ (ring-insert ring 2)
+ (ring-insert ring 3)
+ (ring-resize ring 5)
+ (should (= (ring-size ring) 5))
+ (should (equal (ring-elements ring) '(3 2 1)))))
+
+(ert-deftest ring-resize/grow-empty ()
+ (let ((ring (make-ring 3)))
+ (ring-resize ring 5)
+ (should (= (ring-size ring) 5))
+ (should (equal (ring-elements ring) '()))))
+
+(ert-deftest ring-resize/grow-wrapped-ring ()
+ (let ((ring (make-ring 3)))
+ (ring-insert ring 1)
+ (ring-insert ring 2)
+ (ring-insert ring 3)
+ (ring-insert ring 4)
+ (ring-insert ring 5)
+ (ring-resize ring 5)
+ (should (= (ring-size ring) 5))
+ (should (equal (ring-elements ring) '(5 4 3)))))
+
+(ert-deftest ring-resize/shrink ()
+ (let ((ring (make-ring 5)))
+ (ring-insert ring 1)
+ (ring-insert ring 2)
+ (ring-insert ring 3)
+ (ring-insert ring 4)
+ (ring-insert ring 5)
+ (ring-resize ring 3)
+ (should (= (ring-size ring) 3))
+ (should (equal (ring-elements ring) '(5 4 3)))))
+
(ert-deftest ring-tests-insert ()
(let ((ring (make-ring 2)))
(ring-insert+extend ring :a)