2017-08-11 17:53:27 -06:00
|
|
|
;;; cl-lib-tests.el --- tests for emacs-lisp/cl-lib.el -*- lexical-binding:t -*-
|
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too.
(ert--cl-do-remf, ert--remprop, ert--remove-if-not)
(ert--intersection, ert--set-difference, ert--set-difference-eq)
(ert--union, ert--gensym-counter, ert--gensym-counter)
(ert--coerce-to-vector, ert--remove*, ert--string-position)
(ert--mismatch, ert--subseq): Remove reimplementations of cl funcs.
(ert-make-test-unbound, ert--expand-should-1)
(ert--expand-should, ert--should-error-handle-error)
(should-error, ert--explain-equal-rec)
(ert--plist-difference-explanation, ert-select-tests)
(ert--make-stats, ert--remove-from-list, ert--string-first-line):
Use cl-lib functions rather than reimplementations.
* test/automated/ert-tests.el: Require cl-lib at runtime too.
(ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
(ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
(ert-test-set-functions, ert-test-gensym)
(ert-test-coerce-to-vector, ert-test-string-position)
(ert-test-mismatch): Remove tests.
* test/automated/cl-lib.el: New, split from ert-tests.el.
2013-07-11 09:13:38 -07:00
|
|
|
|
2025-01-01 07:39:17 +00:00
|
|
|
;; Copyright (C) 2013-2025 Free Software Foundation, Inc.
|
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too.
(ert--cl-do-remf, ert--remprop, ert--remove-if-not)
(ert--intersection, ert--set-difference, ert--set-difference-eq)
(ert--union, ert--gensym-counter, ert--gensym-counter)
(ert--coerce-to-vector, ert--remove*, ert--string-position)
(ert--mismatch, ert--subseq): Remove reimplementations of cl funcs.
(ert-make-test-unbound, ert--expand-should-1)
(ert--expand-should, ert--should-error-handle-error)
(should-error, ert--explain-equal-rec)
(ert--plist-difference-explanation, ert-select-tests)
(ert--make-stats, ert--remove-from-list, ert--string-first-line):
Use cl-lib functions rather than reimplementations.
* test/automated/ert-tests.el: Require cl-lib at runtime too.
(ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
(ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
(ert-test-set-functions, ert-test-gensym)
(ert-test-coerce-to-vector, ert-test-string-position)
(ert-test-mismatch): Remove tests.
* test/automated/cl-lib.el: New, split from ert-tests.el.
2013-07-11 09:13:38 -07:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2021-02-08 09:03:27 +01:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too.
(ert--cl-do-remf, ert--remprop, ert--remove-if-not)
(ert--intersection, ert--set-difference, ert--set-difference-eq)
(ert--union, ert--gensym-counter, ert--gensym-counter)
(ert--coerce-to-vector, ert--remove*, ert--string-position)
(ert--mismatch, ert--subseq): Remove reimplementations of cl funcs.
(ert-make-test-unbound, ert--expand-should-1)
(ert--expand-should, ert--should-error-handle-error)
(should-error, ert--explain-equal-rec)
(ert--plist-difference-explanation, ert-select-tests)
(ert--make-stats, ert--remove-from-list, ert--string-first-line):
Use cl-lib functions rather than reimplementations.
* test/automated/ert-tests.el: Require cl-lib at runtime too.
(ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
(ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
(ert-test-set-functions, ert-test-gensym)
(ert-test-coerce-to-vector, ert-test-string-position)
(ert-test-mismatch): Remove tests.
* test/automated/cl-lib.el: New, split from ert-tests.el.
2013-07-11 09:13:38 -07:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2021-02-08 09:03:27 +01:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too.
(ert--cl-do-remf, ert--remprop, ert--remove-if-not)
(ert--intersection, ert--set-difference, ert--set-difference-eq)
(ert--union, ert--gensym-counter, ert--gensym-counter)
(ert--coerce-to-vector, ert--remove*, ert--string-position)
(ert--mismatch, ert--subseq): Remove reimplementations of cl funcs.
(ert-make-test-unbound, ert--expand-should-1)
(ert--expand-should, ert--should-error-handle-error)
(should-error, ert--explain-equal-rec)
(ert--plist-difference-explanation, ert-select-tests)
(ert--make-stats, ert--remove-from-list, ert--string-first-line):
Use cl-lib functions rather than reimplementations.
* test/automated/ert-tests.el: Require cl-lib at runtime too.
(ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
(ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
(ert-test-set-functions, ert-test-gensym)
(ert-test-coerce-to-vector, ert-test-string-position)
(ert-test-mismatch): Remove tests.
* test/automated/cl-lib.el: New, split from ert-tests.el.
2013-07-11 09:13:38 -07:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
Consolidate some cl-lib tests
For discussion, see bug#75633#16 and the following thread:
https://lists.gnu.org/r/emacs-devel/2025-02/msg00053.html
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-lib-test-remprop)
(cl-lib-test-coerce-to-vector, cl-parse-integer): Move here from
cl-lib-tests.el.
(cl-extra-test-remprop): Remove duplicate test, folding body...
(cl-get): ...into this test.
(cl-extra-test-concatenate): Remove duplicate test, folding body...
(cl-concatenate): ...into this test.
* test/lisp/emacs-lisp/cl-lib-tests.el: Update historic commentary.
(cl-lib-test-remprop, cl-lib-test-coerce-to-vector)
(cl-parse-integer): Move to cl-extra-tests.el.
(cl-lib-test-remove-if-not, cl-lib-test-remove)
(cl-lib-test-set-functions, cl-lib-test-string-position)
(cl-lib-test-mismatch, cl-nset-difference): Move to cl-seq-tests.el.
(cl-lib-test-gensym, cl-lib-keyword-names-versus-values)
(cl-lib-empty-keyargs, mystruct, cl-lib-struct-accessors)
(cl-lib-struct-constructors, cl-lib-arglist-performance, cl-the)
(cl-flet-test, cl-lib-test-typep, cl-lib-symbol-macrolet)
(cl-lib-symbol-macrolet-4+5, cl-lib-symbol-macrolet-2)
(cl-lib-symbol-macrolet-hide, cl-lib-defstruct-record): Move to
cl-macs-tests.el.
(cl-lib-test-endp): Remove duplicate test, folding body into
cl-seq-endp-test.
(cl-lib-set-difference): Remove duplicate test, folding body into
cl-set-difference-test.
* test/lisp/emacs-lisp/cl-macs-tests.el: Do not require cl-macs and
pcase.
(mystruct, cl-lib-struct-accessors, cl-lib-struct-constructors)
(cl-lib-arglist-performance, cl-lib-defstruct-record)
(cl-lib-symbol-macrolet, cl-lib-symbol-macrolet-4+5)
(cl-lib-symbol-macrolet-2, cl-lib-symbol-macrolet-hide, cl-flet-test)
(cl-lib-keyword-names-versus-values, cl-lib-empty-keyargs)
(cl-lib-test-gensym, cl-the, cl-lib-test-typep): Move here from
cl-lib-tests.el.
(cl-case-error, cl-case-warning): Fix indentation.
* test/lisp/emacs-lisp/cl-seq-tests.el: Require cl-lib rather than
cl-seq.
(cl-seq-endp-test): Absorb body of cl-lib-test-endp.
(cl-lib-test-remove, cl-lib-test-remove-if-not)
(cl-lib-test-string-position, cl-lib-test-mismatch)
(cl-lib-test-set-functions, cl-nset-difference): Move here from
cl-lib-tests.el.
(cl-set-difference-test): Absorb body of cl-lib-set-difference.
2025-02-02 17:18:52 +01:00
|
|
|
;; Some of these tests were extracted from ert-tests.el, back when ert
|
|
|
|
;; used to reimplement some cl functions.
|
Stop reimplementing a bunch of cl- functions in ert
* lisp/emacs-lisp/ert.el: Require cl-lib at runtime too.
(ert--cl-do-remf, ert--remprop, ert--remove-if-not)
(ert--intersection, ert--set-difference, ert--set-difference-eq)
(ert--union, ert--gensym-counter, ert--gensym-counter)
(ert--coerce-to-vector, ert--remove*, ert--string-position)
(ert--mismatch, ert--subseq): Remove reimplementations of cl funcs.
(ert-make-test-unbound, ert--expand-should-1)
(ert--expand-should, ert--should-error-handle-error)
(should-error, ert--explain-equal-rec)
(ert--plist-difference-explanation, ert-select-tests)
(ert--make-stats, ert--remove-from-list, ert--string-first-line):
Use cl-lib functions rather than reimplementations.
* test/automated/ert-tests.el: Require cl-lib at runtime too.
(ert-test-special-operator-p): Use cl-gensym rather than ert-- version.
(ert-test-remprop, ert-test-remove-if-not, ert-test-remove*)
(ert-test-set-functions, ert-test-gensym)
(ert-test-coerce-to-vector, ert-test-string-position)
(ert-test-mismatch): Remove tests.
* test/automated/cl-lib.el: New, split from ert-tests.el.
2013-07-11 09:13:38 -07:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'ert)
|
|
|
|
|
2025-01-17 09:48:57 -05:00
|
|
|
(ert-deftest cl-lib-test-pushnew ()
|
|
|
|
(let ((list '(1 2 3)))
|
|
|
|
(cl-pushnew 0 list)
|
|
|
|
(should (equal list '(0 1 2 3))))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 7) list :key #'cdr)
|
|
|
|
(should (equal list '((3 7) (1 2) (3 4)) )))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 7) list :key #'car)
|
|
|
|
(should (equal list '((1 2) (3 4)))))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 4) list :test #'equal)
|
|
|
|
(should (equal list '((1 2) (3 4)))))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 5) list :test #'equal)
|
|
|
|
(should (equal list '((3 5) (1 2) (3 4)))))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 4) list :test-not #'equal)
|
|
|
|
(should (equal list '((1 2) (3 4)))))
|
|
|
|
(let ((list '((1 2) (3 4))))
|
|
|
|
(cl-pushnew '(3 5) list :test-not #'equal)
|
|
|
|
(should (equal list '((1 2) (3 4))))))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-values-list ()
|
|
|
|
(let ((list '(:a :b :c)))
|
|
|
|
(should (equal (cl-values-list list) '(:a :b :c))))
|
|
|
|
(let ((not-a-list :a))
|
|
|
|
(should-error (cl-values-list not-a-list) :type 'wrong-type-argument)))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-multiple-value-list ()
|
|
|
|
(should (equal (cl-multiple-value-list 1) 1))
|
|
|
|
(should (equal (cl-multiple-value-list '(1 2 3)) '(1 2 3)))
|
|
|
|
(should (equal (cl-multiple-value-list "string") "string"))
|
|
|
|
(should (equal (cl-multiple-value-list nil) nil))
|
|
|
|
(should (equal (cl-multiple-value-list (list 1 2 3)) '(1 2 3))))
|
|
|
|
|
2014-09-26 08:15:21 +08:00
|
|
|
(ert-deftest cl-digit-char-p ()
|
* test/automated/cl-lib-tests.el: Add tests for plusp, second, ...
(cl-lib-test-plusp, cl-lib-test-minusp)
(cl-lib-test-oddp, cl-lib-test-evenp, cl-lib-test-first)
(cl-lib-test-second, cl-lib-test-third, cl-lib-test-fourth)
(cl-lib-test-fifth, cl-lib-test-sixth, cl-lib-test-seventh)
(cl-lib-test-eighth, cl-lib-test-ninth, cl-lib-test-tenth)
(cl-lib-test-endp, cl-lib-test-nth-value)
(cl-lib-nth-value-test-multiple-values, cl-test-caaar, cl-test-caadr)
(cl-test-ldiff): New tests.
(cl-digit-char-p): Tighten the test.
2015-03-09 23:14:36 -04:00
|
|
|
(should (eql 3 (cl-digit-char-p ?3)))
|
|
|
|
(should (eql 10 (cl-digit-char-p ?a 11)))
|
|
|
|
(should (eql 10 (cl-digit-char-p ?A 11)))
|
2014-09-26 08:15:21 +08:00
|
|
|
(should-not (cl-digit-char-p ?a))
|
* test/automated/cl-lib-tests.el: Add tests for plusp, second, ...
(cl-lib-test-plusp, cl-lib-test-minusp)
(cl-lib-test-oddp, cl-lib-test-evenp, cl-lib-test-first)
(cl-lib-test-second, cl-lib-test-third, cl-lib-test-fourth)
(cl-lib-test-fifth, cl-lib-test-sixth, cl-lib-test-seventh)
(cl-lib-test-eighth, cl-lib-test-ninth, cl-lib-test-tenth)
(cl-lib-test-endp, cl-lib-test-nth-value)
(cl-lib-nth-value-test-multiple-values, cl-test-caaar, cl-test-caadr)
(cl-test-ldiff): New tests.
(cl-digit-char-p): Tighten the test.
2015-03-09 23:14:36 -04:00
|
|
|
(should (eql 32 (cl-digit-char-p ?w 36)))
|
|
|
|
(should-error (cl-digit-char-p ?a 37) :type 'args-out-of-range)
|
|
|
|
(should-error (cl-digit-char-p ?a 1) :type 'args-out-of-range))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-first ()
|
|
|
|
(should (null (cl-first '())))
|
|
|
|
(should (= 4 (cl-first '(4))))
|
|
|
|
(should (= 4 (cl-first '(4 2))))
|
|
|
|
(should-error (cl-first "42") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-second ()
|
|
|
|
(should (null (cl-second '())))
|
|
|
|
(should (null (cl-second '(4))))
|
|
|
|
(should (= 2 (cl-second '(1 2))))
|
|
|
|
(should (= 2 (cl-second '(1 2 3))))
|
|
|
|
(should-error (cl-second "1 2 3") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-third ()
|
|
|
|
(should (null (cl-third '())))
|
|
|
|
(should (null (cl-third '(1 2))))
|
|
|
|
(should (= 3 (cl-third '(1 2 3))))
|
|
|
|
(should (= 3 (cl-third '(1 2 3 4))))
|
|
|
|
(should-error (cl-third "123") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-fourth ()
|
|
|
|
(should (null (cl-fourth '())))
|
|
|
|
(should (null (cl-fourth '(1 2 3))))
|
|
|
|
(should (= 4 (cl-fourth '(1 2 3 4))))
|
|
|
|
(should (= 4 (cl-fourth '(1 2 3 4 5))))
|
|
|
|
(should-error (cl-fourth "1234") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-fifth ()
|
|
|
|
(should (null (cl-fifth '())))
|
|
|
|
(should (null (cl-fifth '(1 2 3 4))))
|
|
|
|
(should (= 5 (cl-fifth '(1 2 3 4 5))))
|
|
|
|
(should (= 5 (cl-fifth '(1 2 3 4 5 6))))
|
|
|
|
(should-error (cl-fifth "12345") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-sixth ()
|
|
|
|
(should (null (cl-sixth '())))
|
|
|
|
(should (null (cl-sixth '(1 2 3 4 5))))
|
|
|
|
(should (= 6 (cl-sixth '(1 2 3 4 5 6))))
|
|
|
|
(should (= 6 (cl-sixth '(1 2 3 4 5 6 7))))
|
|
|
|
(should-error (cl-sixth "123456") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-seventh ()
|
|
|
|
(should (null (cl-seventh '())))
|
|
|
|
(should (null (cl-seventh '(1 2 3 4 5 6))))
|
|
|
|
(should (= 7 (cl-seventh '(1 2 3 4 5 6 7))))
|
|
|
|
(should (= 7 (cl-seventh '(1 2 3 4 5 6 7 8))))
|
|
|
|
(should-error (cl-seventh "1234567") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-eighth ()
|
|
|
|
(should (null (cl-eighth '())))
|
|
|
|
(should (null (cl-eighth '(1 2 3 4 5 6 7))))
|
|
|
|
(should (= 8 (cl-eighth '(1 2 3 4 5 6 7 8))))
|
|
|
|
(should (= 8 (cl-eighth '(1 2 3 4 5 6 7 8 9))))
|
|
|
|
(should-error (cl-eighth "12345678") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-ninth ()
|
|
|
|
(should (null (cl-ninth '())))
|
|
|
|
(should (null (cl-ninth '(1 2 3 4 5 6 7 8))))
|
|
|
|
(should (= 9 (cl-ninth '(1 2 3 4 5 6 7 8 9))))
|
|
|
|
(should (= 9 (cl-ninth '(1 2 3 4 5 6 7 8 9 10))))
|
|
|
|
(should-error (cl-ninth "123456789") :type 'wrong-type-argument))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-tenth ()
|
|
|
|
(should (null (cl-tenth '())))
|
|
|
|
(should (null (cl-tenth '(1 2 3 4 5 6 7 8 9))))
|
|
|
|
(should (= 10 (cl-tenth '(1 2 3 4 5 6 7 8 9 10))))
|
|
|
|
(should (= 10 (cl-tenth '(1 2 3 4 5 6 7 8 9 10 11))))
|
|
|
|
(should-error (cl-tenth "1234567890") :type 'wrong-type-argument))
|
|
|
|
|
2025-01-17 09:48:57 -05:00
|
|
|
(ert-deftest cl-lib-test-mapcar ()
|
|
|
|
(should (equal (cl-mapcar #'1+ '(1 2 3)) '(2 3 4)))
|
|
|
|
(should (equal (cl-mapcar #'+ '(1 2 3) '(4 5 6)) '(5 7 9)))
|
|
|
|
(should (equal (cl-mapcar #'+ '(1 2 3) '(4 5)) '(5 7)))
|
|
|
|
(should (equal (cl-mapcar #'+ '() '()) '()))
|
|
|
|
(should-error (cl-mapcar #'+ 1 '(4 5 6)))
|
|
|
|
(should-error (cl-mapcar #'+ '(1 2 3) 4)))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-list* ()
|
|
|
|
(should (equal (cl-list* 'a) 'a))
|
|
|
|
(should (equal (cl-list* 'a 'b) '(a . b)))
|
|
|
|
(should (equal (cl-list* 'a 'b 'c 'd) '(a b c . d)))
|
|
|
|
(should (equal (cl-list* 'a 'b '(c d)) '(a b c d))))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-copy-list ()
|
|
|
|
(let ((original '(1 2 . 3))
|
|
|
|
(result (cl-copy-list '(1 2 . 3))))
|
|
|
|
(and (should (equal original result))
|
|
|
|
(not (eq original result)))))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-subst ()
|
|
|
|
(should (equal (cl-subst 'x 'a '(a b c)) '(x b c)))
|
|
|
|
(should (equal (cl-subst 'x 'a '(a b a c)) '(x b x c)))
|
|
|
|
(should (equal (cl-subst 'x 'a '(b c d)) '(b c d)))
|
|
|
|
(should (equal (cl-subst 'x 'a '(a b (a c) d)) '(x b (x c) d)))
|
|
|
|
(should (equal (cl-subst "a" "A" '("a" "b" "c" "a") :test #'equal) '("a" "b" "c" "a"))))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-acons ()
|
|
|
|
(should (equal (cl-acons 'key 'value '()) '((key . value))))
|
|
|
|
(should (equal (cl-acons 'key 'value '((a . 1) (b . 2))) '((key . value) (a . 1) (b . 2))))
|
|
|
|
(should (equal (cl-acons 'a 1 '((a . 1) (b . 2))) '((a . 1) (a . 1) (b . 2))))
|
|
|
|
(should (equal (cl-acons nil 'value '((a . 1) (b . 2))) '((nil . value) (a . 1) (b . 2))))
|
|
|
|
(should (equal (cl-acons 'key nil '((a . 1) (b . 2))) '((key . nil) (a . 1) (b . 2)))))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-test-pairlis ()
|
|
|
|
(should (equal (cl-pairlis '(a b c) '(1 2 3)) '((a . 1) (b . 2) (c . 3))))
|
|
|
|
(should (equal (cl-pairlis '(a b c d) '(1 2 3)) '((a . 1) (b . 2) (c . 3))))
|
|
|
|
(should (equal (cl-pairlis '(a b c) '(1 2 3 4)) '((a . 1) (b . 2) (c . 3))))
|
|
|
|
(should (equal (cl-pairlis '(a b c) '(1 2 3) '((d . 4) (e . 5))) '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5))))
|
|
|
|
(should (equal (cl-pairlis '() '(1 2 3)) '()))
|
|
|
|
(should (equal (cl-pairlis '(a b c) '()) '()))
|
|
|
|
(should (equal (cl-pairlis '(a nil c) '(1 2 3)) '((a . 1) (nil . 2) (c . 3))))
|
|
|
|
(should (equal (cl-pairlis '(a b c) '(1 nil 3)) '((a . 1) (b) (c . 3)))))
|
|
|
|
|
* test/automated/cl-lib-tests.el: Add tests for plusp, second, ...
(cl-lib-test-plusp, cl-lib-test-minusp)
(cl-lib-test-oddp, cl-lib-test-evenp, cl-lib-test-first)
(cl-lib-test-second, cl-lib-test-third, cl-lib-test-fourth)
(cl-lib-test-fifth, cl-lib-test-sixth, cl-lib-test-seventh)
(cl-lib-test-eighth, cl-lib-test-ninth, cl-lib-test-tenth)
(cl-lib-test-endp, cl-lib-test-nth-value)
(cl-lib-nth-value-test-multiple-values, cl-test-caaar, cl-test-caadr)
(cl-test-ldiff): New tests.
(cl-digit-char-p): Tighten the test.
2015-03-09 23:14:36 -04:00
|
|
|
(ert-deftest cl-lib-test-nth-value ()
|
|
|
|
(let ((vals (cl-values 2 3)))
|
|
|
|
(should (= (cl-nth-value 0 vals) 2))
|
|
|
|
(should (= (cl-nth-value 1 vals) 3))
|
|
|
|
(should (null (cl-nth-value 2 vals)))
|
|
|
|
(should-error (cl-nth-value 0.0 vals) :type 'wrong-type-argument)))
|
|
|
|
|
|
|
|
(ert-deftest cl-lib-nth-value-test-multiple-values ()
|
|
|
|
"While CL multiple values are an alias to list, these won't work."
|
|
|
|
:expected-result :failed
|
2022-12-16 12:17:33 +01:00
|
|
|
(should (equal (cl-nth-value 0 '(2 3)) '(2 3)))
|
* test/automated/cl-lib-tests.el: Add tests for plusp, second, ...
(cl-lib-test-plusp, cl-lib-test-minusp)
(cl-lib-test-oddp, cl-lib-test-evenp, cl-lib-test-first)
(cl-lib-test-second, cl-lib-test-third, cl-lib-test-fourth)
(cl-lib-test-fifth, cl-lib-test-sixth, cl-lib-test-seventh)
(cl-lib-test-eighth, cl-lib-test-ninth, cl-lib-test-tenth)
(cl-lib-test-endp, cl-lib-test-nth-value)
(cl-lib-nth-value-test-multiple-values, cl-test-caaar, cl-test-caadr)
(cl-test-ldiff): New tests.
(cl-digit-char-p): Tighten the test.
2015-03-09 23:14:36 -04:00
|
|
|
(should (= (cl-nth-value 0 1) 1))
|
|
|
|
(should (null (cl-nth-value 1 1)))
|
|
|
|
(should-error (cl-nth-value -1 (cl-values 2 3)) :type 'args-out-of-range)
|
|
|
|
(should (string= (cl-nth-value 0 "only lists") "only lists")))
|
|
|
|
|
|
|
|
(ert-deftest cl-test-ldiff ()
|
|
|
|
(let ((l '(1 2 3)))
|
|
|
|
(should (null (cl-ldiff '() '())))
|
|
|
|
(should (null (cl-ldiff '() l)))
|
|
|
|
(should (null (cl-ldiff l l)))
|
|
|
|
(should (equal l (cl-ldiff l '())))
|
|
|
|
;; must be part of the list
|
|
|
|
(should (equal l (cl-ldiff l '(2 3))))
|
|
|
|
(should (equal '(1) (cl-ldiff l (nthcdr 1 l))))
|
|
|
|
;; should return a copy
|
|
|
|
(should-not (eq (cl-ldiff l '()) l))))
|
2014-09-26 08:15:21 +08:00
|
|
|
|
2015-04-30 23:48:49 +02:00
|
|
|
(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)))
|
2023-01-03 14:26:44 +01:00
|
|
|
(with-suppressed-warnings ((suspicious memql))
|
2022-12-17 19:13:13 +01:00
|
|
|
(should (equal '(2 1 (2)) (cl-adjoin 2 '(1 (2))))))
|
2015-04-30 23:48:49 +02:00
|
|
|
;; 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
|
|
|
|
|
2015-05-05 12:25:18 -07:00
|
|
|
;; according to CLtL2 passing both :test and :test-not should signal error
|
2015-04-30 23:48:49 +02:00
|
|
|
;;(should-error (cl-adjoin 3 nums :test 'myfn-p :test-not myfn-p))
|
|
|
|
|
|
|
|
;; own :key fn
|
Prefer oddp/evenp to cl-oddp/cl-evenp
* lisp/calc/calc-ext.el (math-oddp):
* lisp/calc/calc-misc.el (math-evenp):
* lisp/calendar/todo-mode.el
(todo-adjusted-category-label-length, todo-insert-category-line)
(todo-update-categories-display):
* lisp/emacs-lisp/cl-macs.el (cl-defstruct):
* lisp/net/gnutls.el (open-gnutls-stream):
* lisp/tab-line.el (tab-line-tab-face-inactive-alternating):
* test/lisp/auth-source-tests.el
(auth-source-test-macos-keychain-search):
* test/lisp/emacs-lisp/cl-extra-tests.el (cl-extra-test-notany)
(cl-extra-test-notevery):
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-adjoin-test):
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-collect)
(cl-macs-loop-append/nconc, cl-macs-loop-when)
(cl-macs-loop-if):
* test/lisp/emacs-lisp/cl-seq-tests.el (cl-seq-remove-test)
(cl-remove-if-test, cl-remove-if-not-test, cl-seq-delete-test)
(cl-delete-if-test, cl-delete-if-not-test)
(cl-seq-substitute-if-test, cl-seq-substitute-if-not-test)
(cl-find-if-test, cl-find-if-not-test, cl-position-if-test)
(cl-seq-count-test, cl-count-if-test, cl-count-if-not-test)
(cl-member-if-test, cl-member-if-not-test, cl-assoc-if-test)
(cl-assoc-if-not-test, cl-rassoc-if-test)
(cl-rassoc-if-not-test):
* test/src/treesit-tests.el (treesit-search-forward-predicate):
Prefer oddp/evenp to cl-oddp/cl-evenp where possible.
* lisp/calc/calc-ext.el (cl-lib):
* lisp/calc/calc-misc.el (cl-lib): Don't require.
2025-02-17 03:33:54 +01:00
|
|
|
(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)))))
|
2015-04-30 23:48:49 +02:00
|
|
|
|
|
|
|
;; 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)))
|
|
|
|
|
2017-03-24 09:21:52 -04:00
|
|
|
(ert-deftest old-struct ()
|
|
|
|
(cl-defstruct foo x)
|
2023-09-06 13:00:30 +02:00
|
|
|
(with-suppressed-warnings ((obsolete cl-old-struct-compat-mode))
|
|
|
|
(let ((x (vector 'cl-struct-foo))
|
|
|
|
(saved cl-old-struct-compat-mode))
|
|
|
|
(cl-old-struct-compat-mode -1)
|
|
|
|
(should (eq (type-of x) 'vector))
|
2017-03-24 09:21:52 -04:00
|
|
|
|
2023-09-06 13:00:30 +02:00
|
|
|
(cl-old-struct-compat-mode 1)
|
|
|
|
(defvar cl-struct-foo)
|
|
|
|
(let ((cl-struct-foo (cl--struct-get-class 'foo)))
|
|
|
|
(setf (symbol-function 'cl-struct-foo) :quick-object-witness-check)
|
|
|
|
(should (eq (type-of x) 'foo))
|
|
|
|
(should (eq (type-of (vector 'foo)) 'vector)))
|
2017-03-24 09:21:52 -04:00
|
|
|
|
2023-09-06 13:00:30 +02:00
|
|
|
(cl-old-struct-compat-mode (if saved 1 -1)))))
|
2017-03-24 09:21:52 -04:00
|
|
|
|
|
|
|
(ert-deftest cl-lib-old-struct ()
|
2023-09-06 13:00:30 +02:00
|
|
|
(with-suppressed-warnings ((obsolete cl-old-struct-compat-mode))
|
|
|
|
(let ((saved cl-old-struct-compat-mode))
|
|
|
|
(cl-old-struct-compat-mode -1)
|
|
|
|
(cl-struct-define 'foo "" 'cl-structure-object nil nil nil
|
|
|
|
'cl-struct-foo-tags 'cl-struct-foo t)
|
|
|
|
(should cl-old-struct-compat-mode)
|
|
|
|
(cl-old-struct-compat-mode (if saved 1 -1)))))
|
2017-03-24 09:21:52 -04:00
|
|
|
|
2021-12-02 10:19:10 +01:00
|
|
|
(ert-deftest cl-constantly ()
|
|
|
|
(should (equal (mapcar (cl-constantly 3) '(a b c d))
|
|
|
|
'(3 3 3 3))))
|
|
|
|
|
2017-08-11 17:53:27 -06:00
|
|
|
;;; cl-lib-tests.el ends here
|