From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?UHJ6ZW15c8WCYXcgV29qbm93c2tp?= Newsgroups: gmane.emacs.devel Subject: [PATCH] cl-adjoin tests Date: Thu, 30 Apr 2015 23:53:33 +0200 Message-ID: <5542A45D.3000602@cumego.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000101010001000407060002" X-Trace: ger.gmane.org 1430430939 9042 80.91.229.3 (30 Apr 2015 21:55:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 30 Apr 2015 21:55:39 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 30 23:55:31 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YnwQc-0005rU-Cp for ged-emacs-devel@m.gmane.org; Thu, 30 Apr 2015 23:55:30 +0200 Original-Received: from localhost ([::1]:46034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwQb-0006wW-DL for ged-emacs-devel@m.gmane.org; Thu, 30 Apr 2015 17:55:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwOu-0003zF-KU for emacs-devel@gnu.org; Thu, 30 Apr 2015 17:53:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnwOq-0003E7-OE for emacs-devel@gnu.org; Thu, 30 Apr 2015 17:53:44 -0400 Original-Received: from smtp12.iq.pl ([86.111.240.243]:38355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwOq-0003D0-DO for emacs-devel@gnu.org; Thu, 30 Apr 2015 17:53:40 -0400 Original-Received: (qmail 22141 invoked from network); 30 Apr 2015 21:53:34 -0000 Original-Received: from unknown (HELO [192.168.1.106]) (esperanto@cumego.com@[159.205.25.146]) (envelope-sender ) by smtp71.iq.pl with AES128-SHA encrypted SMTP for ; 30 Apr 2015 21:53:34 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.111.240.243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:186070 Archived-At: This is a multi-part message in MIME format. --------------000101010001000407060002 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hello everybody, Here's a patch with cl-adjoin tests. Cheers, Przemysław --------------000101010001000407060002 Content-Type: text/x-patch; name="0001-Add-cl-adjoin-tests.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Add-cl-adjoin-tests.patch" >From 6d2e7cc0da5fffd3196c1f06f8e35e99bb24f343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Wojnowski?= 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 --------------000101010001000407060002--