Prefer HTTPS to FTP and HTTP in documentation
[emacs.git] / test / lisp / emacs-lisp / cl-extra-tests.el
blobc37caa1aab7b53495df19f4b32190cf217517e60
1 ;;; cl-extra-tests.el --- tests for emacs-lisp/cl-extra.el -*- lexical-binding:t -*-
3 ;; Copyright (C) 2013-2017 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `https://www.gnu.org/licenses/'.
20 ;;; Code:
22 (require 'cl-lib)
23 (require 'ert)
25 (ert-deftest cl-get ()
26 (put 'cl-get-test 'x 1)
27 (put 'cl-get-test 'y nil)
28 (should (eq (cl-get 'cl-get-test 'x) 1))
29 (should (eq (cl-get 'cl-get-test 'y :none) nil))
30 (should (eq (cl-get 'cl-get-test 'z :none) :none)))
32 (ert-deftest cl-getf ()
33 (let ((plist '(x 1 y nil)))
34 (should (eq (cl-getf plist 'x) 1))
35 (should (eq (cl-getf plist 'y :none) nil))
36 (should (eq (cl-getf plist 'z :none) :none))))
38 (ert-deftest cl-extra-test-mapc ()
39 (let ((lst '(a b c))
40 (lst2 '(d e f))
41 (lst3 '(1 2 3))
42 (fn1 (lambda (_x) nil))
43 (fn2 (lambda (_x _y) nil))
44 (fn3 (lambda (_x _y _z) nil)))
45 (should (equal lst (cl-mapc fn1 lst)))
46 (should (equal lst (cl-mapc fn2 lst lst2)))
47 (should (equal lst (cl-mapc fn3 lst lst2 lst3)))))
49 (ert-deftest cl-extra-test-mapl ()
50 (let ((lst '(a b c))
51 (lst2 '(d e f))
52 (lst3 '(1 2 3))
53 (fn1 (lambda (x) (should (consp x))))
54 (fn2 (lambda (x y) (should (and (consp x) (consp y)))))
55 (fn3 (lambda (x y z) (should (and (consp x) (consp y) (consp z))))))
56 (should (equal lst (cl-mapl fn1 lst)))
57 (should (equal lst (cl-mapl fn2 lst lst2)))
58 (should (equal lst (cl-mapl fn3 lst lst2 lst3)))))
60 (ert-deftest cl-extra-test-mapcar ()
61 (let ((lst '(a b c))
62 (lst2 '(d e f))
63 (lst3 '(1 2 3))
64 (fn1 (lambda (x) x))
65 (fn2 (lambda (_x y) y))
66 (fn3 (lambda (_x _y z) z)))
67 (should (equal lst (cl-mapcar fn1 lst)))
68 (should (equal lst2 (cl-mapcar fn2 lst lst2)))
69 (should (equal lst3 (cl-mapcar fn3 lst lst2 lst3)))))
71 (ert-deftest cl-extra-test-map ()
72 (let ((lst '(a b c))
73 (lst2 '(d e f))
74 (lst3 '(1 2 3))
75 (fn1 (lambda (x) x))
76 (fn2 (lambda (_x y) y))
77 (fn3 (lambda (x _y _z) (string-to-char (format "%S" x)))))
78 (should (equal lst (cl-map 'list fn1 lst)))
79 (should (equal (vconcat lst2) (cl-map 'vector fn2 lst lst2)))
80 (should (equal (mapconcat (lambda (x) (format "%S" x)) lst "")
81 (cl-map 'string fn3 lst lst2 lst3)))))
83 (ert-deftest cl-extra-test-maplist ()
84 (let ((lst '(a b c))
85 (lst2 '(d e f))
86 (lst3 '(1 2 3))
87 (fn1 (lambda (x) (should (consp x)) x))
88 (fn2 (lambda (x y) (should (and (consp x) (consp y))) y))
89 (fn3 (lambda (x y z) (should (and (consp x) (consp y) (consp z))) z)))
90 (should (equal (list lst (cdr lst) (cddr lst))
91 (cl-maplist fn1 lst)))
92 (should (equal (list lst2 (cdr lst2) (cddr lst2))
93 (cl-maplist fn2 lst lst2)))
94 (should (equal (list lst3 (cdr lst3) (cddr lst3))
95 (cl-maplist fn3 lst lst2 lst3)))))
97 ;;; cl-extra-tests.el ends here