* [PATCH] cl-adjoin tests
@ 2015-04-30 21:53 Przemysław Wojnowski
2015-05-01 17:25 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: Przemysław Wojnowski @ 2015-04-30 21:53 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 76 bytes --]
Hello everybody,
Here's a patch with cl-adjoin tests.
Cheers,
Przemysław
[-- Attachment #2: 0001-Add-cl-adjoin-tests.patch --]
[-- Type: text/x-patch, Size: 2992 bytes --]
From 6d2e7cc0da5fffd3196c1f06f8e35e99bb24f343 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Przemys=C5=82aw=20Wojnowski?= <esperanto@cumego.com>
Date: Thu, 30 Apr 2015 23:48:49 +0200
Subject: [PATCH] ; Add cl-adjoin tests
* test/automated/cl-lib-tests.el (cl-lib-adjoin-test): New tests.
---
test/automated/cl-lib-tests.el | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/test/automated/cl-lib-tests.el b/test/automated/cl-lib-tests.el
index ce0e591..d272f3a 100644
--- a/test/automated/cl-lib-tests.el
+++ b/test/automated/cl-lib-tests.el
@@ -422,6 +422,47 @@
;; should return a copy
(should-not (eq (cl-ldiff l '()) l))))
+(ert-deftest cl-lib-adjoin-test ()
+ (let ((nums '(1 2))
+ (myfn-p '=))
+ ;; add non-existing item to the front
+ (should (equal '(3 1 2) (cl-adjoin 3 nums)))
+ ;; just add - don't copy rest
+ (should (eq nums (cdr (cl-adjoin 3 nums))))
+ ;; add only when not already there
+ (should (eq nums (cl-adjoin 2 nums)))
+ (should (equal '(2 1 (2)) (cl-adjoin 2 '(1 (2)))))
+ ;; default test function is eql
+ (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums)))
+ ;; own :test function - returns true if match
+ (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums :test nil))) ;defaults to eql
+ (should (eq nums (cl-adjoin 2 nums :test myfn-p))) ;match
+ (should (equal '(3 1 2) (cl-adjoin 3 nums :test myfn-p))) ;no match
+ ;; own :test-not function - returns false if match
+ (should (equal '(1.0 1 2) (cl-adjoin 1.0 nums :test-not nil))) ;defaults to eql
+ (should (equal '(2 2) (cl-adjoin 2 '(2) :test-not myfn-p))) ; no match
+ (should (eq nums (cl-adjoin 2 nums :test-not myfn-p))) ; 1 matches
+ (should (eq nums (cl-adjoin 3 nums :test-not myfn-p))) ; 1 and 2 matches
+
+ ;; according to CLTL2 passing both :test and :test-not should signal error
+ ;;(should-error (cl-adjoin 3 nums :test 'myfn-p :test-not myfn-p))
+
+ ;; own :key fn
+ (should (eq nums (cl-adjoin 3 nums :key (lambda (x) (if (evenp x) (1+ x) x)))))
+ (should (equal '(3 1 2) (cl-adjoin 3 nums :key (lambda (x) (if (evenp x) (+ 2 x) x)))))
+
+ ;; convert using :key, then compare with :test
+ (should (eq nums (cl-adjoin 1 nums :key 'int-to-string :test 'string=)))
+ (should (equal '(3 1 2) (cl-adjoin 3 nums :key 'int-to-string :test 'string=)))
+ (should-error (cl-adjoin 3 nums :key 'int-to-string :test myfn-p)
+ :type 'wrong-type-argument)
+
+ ;; convert using :key, then compare with :test-not
+ (should (eq nums (cl-adjoin 3 nums :key 'int-to-string :test-not 'string=)))
+ (should (equal '(1 1) (cl-adjoin 1 '(1) :key 'int-to-string :test-not 'string=)))
+ (should-error (cl-adjoin 1 nums :key 'int-to-string :test-not myfn-p)
+ :type 'wrong-type-argument)))
+
(ert-deftest cl-parse-integer ()
(should-error (cl-parse-integer "abc"))
(should (null (cl-parse-integer "abc" :junk-allowed t)))
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-01 17:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-30 21:53 [PATCH] cl-adjoin tests Przemysław Wojnowski
2015-05-01 17:25 ` Stefan Monnier
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.