
e65c307
* src/font.c (QCuser_spec): Add missing colon to :user-spec.c8b868b
Don't start the 'midnight' timer twice278c8a7
* src/xwidget.c (Fxwidget_resize): Fix inappropriate use of X...e5c17f4
Fix todo-mode category movementbc70fda
* lisp/xt-mouse.el (xterm-mouse-utf-8): Add :version.cf40f38
Ignore non-nil. non-cons values of unread-command-events8ee4c52
Improve documentatuon of 'truncate-partial-width-windows'fb9a62c
* src/ftfont.c (ftfont_shape_by_flt): Parenthesize as per GNU...1e1ea22
Fix 'dired-goto-file' in Dired buffers produced by find-dired3a13472
Fix map-put and map-delete for alists (Bug#23105)422c3da
Minor copyedits of documentation for temporary displays90fb9b3
Add customization option for using UTF-8 coordinates in xt-mousef14d463
Minor doc string fixes in replace.ele70ee9d
Fix scrolling upwards with 'xwidget-webkit-browse-url'44782de
Fix display of Indic scripts326c64f
Fix splash screen display at startup7ab2a97
; In NEWS mention new display of minibuffer completions windowa1cd84c
Describe temporary displays in Emacs manual5ec1056
Avoid stray As next to IDLW icons45577d5
Avoid GTK 3 crash with icons and maskse99ff6e
* lisp/minibuffer.el (minibuffer-completion-help): Use fit-wi...077b78c
Define make_save_ptr_ptr unconditionally20a1003
Preserve current buffer when popping up TTY menus7eba90c
Improve font selection by family on MS-Windows73d213f
Comint, term, and compile now set EMACS9524ec5
Ignore more merges when generating ChangeLogad250f2
Sync with gnulibc0165ea
Resurrect GNUS-NEWS autogeneration1e5327c
; Backport ChangeLog.2 fixes from mastere643977
Make `toggle-frame-maximized' respect the dock on OS X (bug#2...38a43f1
Fix bug in displaying header line with a box face91e6676
Fix an Isearch var to be a string (Bug#23038)76ef522
Fix (args-out-of-range 1) error in cursor-sensor--detect8a35f83
Render empty <ul><li><ul> correctlyd8b2ce5
Ignore invalid base64 encoded embedded images52ba24b
Fix <p> and <div> newlines with or without <li> in shrb8ea08b
Avoid errors in 'newline'fc3cd53
Fix Bug#23032dd2737b
Adjudicate review comments in abbrevs.texi26f9c50
Fixup the "normal" matcher; highlight global var symbols, too413e73b
; Small theme additionscd950da
Honor prefix arg in doc-view-next-line-or-next-pageed909c0
; Spelling fixes6da3a6d
Port to strict C99 offsetofde7601f
Port to GTK with strict C11 compiler658aa2d
Port to GTK with strict C99 compiler1df7173
Avoid screen artifacts with new OS X visible bell after scrol...7a2edd3
Merge branch 'emacs-25' of git.sv.gnu.org:/srv/git/emacs into...dca240a
Suppress some Tramp tests for OSX, do not merge with master9094304
* lisp/progmodes/xref.el (xref-buffer-name, xref--window): Mo...cbedfc2
* lisp/gnus/mm-decode.el (gnus-format-message): Autoload it.005ac7c
* lisp/mail/rmail.el (rmail-mime-entity-truncated): Declare.9ab03f2
; Auto-commit of loaddefs files.56df617
Address compilation warnings due to 2016-01-03 mml refactoring.a1ef911
* lisp/emacs-lisp/smie.el (smie-indent-keyword): Don't burp i...79ae7fb
* lisp/dired-x.el (dired-omit-here-always): Correct error mes...253929f
* lisp/dired-x.el (dired-omit-here-always): Replace undefined...ce53389
* lisp/xml.el (xml-parse-tag-1): Replace undefined function.d6d164f
Avoid segfaults due to frame image cache being absentbc7f6f6
Improve documentation of glyphless-character display6b6916e
; * src/xdisp.c (with_echo_area_buffer): Fix typos in comments.ee9a1f7
Support safe navigation operator in non-SMIE indentation codec3ed95b
Move xsd:base64Binary decoding fix to debbugs.el 0.9.12036be4
Fix Ruby's operator precedence1d686c2
(ruby-interpolation-inside-another-interpolation): New failin...7950e1d
Port to clang 3.7.0 on x86-64218ae59
* test/automated/package-test.el (package-test-signed): Tweak...ba33b7c
Sync with gnulib38b276d
Fix startup of "emacs -nw" on systems that CANNOT_DUMPdbfbedd
Do not tokenize a comment before continuation as ';'0403620
Don't misindent arguments of a method call inside continuatione6776f8
* src/keyboard.c (echo_keystrokes_p): Don't test cursor_in_ec...8475f3d
ASCII-only etc/NEWS etc.5cc6919
Fix a cacheing bug, which led to inordinately slow c-beginnin...0ce37ea
Fix Isearch prompt when invoked with an argumentf3033d4
Fix a typo in the Emacs manual4235d2d
Curved quotes in etc/NEWS etc.26b56dc
Fix some single quotes in documentation80ec484
Make lisp-completion-at-point's argument optional9d463ae
Tweak the left precedence of '=>'5b705bc
Indent '.' relative to the first sibling expression04f5525
Make '.' associative, for easier sexp navigationba24c99
Revert "Simplify "Visit New File" to "New File""
338 lines
11 KiB
EmacsLisp
338 lines
11 KiB
EmacsLisp
;;; map-tests.el --- Tests for map.el -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
|
|
|
|
;; Author: Nicolas Petton <nicolas@petton.fr>
|
|
;; Maintainer: emacs-devel@gnu.org
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; 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.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Tests for map.el
|
|
|
|
;;; Code:
|
|
|
|
(require 'ert)
|
|
(require 'map)
|
|
|
|
(defmacro with-maps-do (var &rest body)
|
|
"Successively bind VAR to an alist, vector and hash-table.
|
|
Each map is built from the following alist data:
|
|
'((0 . 3) (1 . 4) (2 . 5)).
|
|
Evaluate BODY for each created map.
|
|
|
|
\(fn (var map) body)"
|
|
(declare (indent 1) (debug t))
|
|
(let ((alist (make-symbol "alist"))
|
|
(vec (make-symbol "vec"))
|
|
(ht (make-symbol "ht")))
|
|
`(let ((,alist (list (cons 0 3)
|
|
(cons 1 4)
|
|
(cons 2 5)))
|
|
(,vec (vector 3 4 5))
|
|
(,ht (make-hash-table)))
|
|
(puthash 0 3 ,ht)
|
|
(puthash 1 4 ,ht)
|
|
(puthash 2 5 ,ht)
|
|
(dolist (,var (list ,alist ,vec ,ht))
|
|
,@body))))
|
|
|
|
(ert-deftest test-map-elt ()
|
|
(with-maps-do map
|
|
(should (= 3 (map-elt map 0)))
|
|
(should (= 4 (map-elt map 1)))
|
|
(should (= 5 (map-elt map 2)))
|
|
(should (null (map-elt map -1)))
|
|
(should (null (map-elt map 4)))))
|
|
|
|
(ert-deftest test-map-elt-default ()
|
|
(with-maps-do map
|
|
(should (= 5 (map-elt map 7 5)))))
|
|
|
|
(ert-deftest test-map-elt-with-nil-value ()
|
|
(should (null (map-elt '((a . 1)
|
|
(b))
|
|
'b
|
|
'2))))
|
|
|
|
(ert-deftest test-map-put ()
|
|
(with-maps-do map
|
|
(setf (map-elt map 2) 'hello)
|
|
(should (eq (map-elt map 2) 'hello)))
|
|
(with-maps-do map
|
|
(map-put map 2 'hello)
|
|
(should (eq (map-elt map 2) 'hello)))
|
|
(let ((ht (make-hash-table)))
|
|
(setf (map-elt ht 2) 'a)
|
|
(should (eq (map-elt ht 2)
|
|
'a)))
|
|
(let ((alist '((0 . a) (1 . b) (2 . c))))
|
|
(setf (map-elt alist 2) 'a)
|
|
(should (eq (map-elt alist 2)
|
|
'a)))
|
|
(let ((vec [3 4 5]))
|
|
(should-error (setf (map-elt vec 3) 6))))
|
|
|
|
(ert-deftest test-map-put-alist-new-key ()
|
|
"Regression test for Bug#23105."
|
|
(let ((alist '((0 . a))))
|
|
(map-put alist 2 'b)
|
|
(should (eq (map-elt alist 2)
|
|
'b))))
|
|
|
|
(ert-deftest test-map-put-return-value ()
|
|
(let ((ht (make-hash-table)))
|
|
(should (eq (map-put ht 'a 'hello) 'hello))))
|
|
|
|
(ert-deftest test-map-delete ()
|
|
(with-maps-do map
|
|
(map-delete map 1)
|
|
(should (null (map-elt map 1))))
|
|
(with-maps-do map
|
|
(map-delete map -2)
|
|
(should (null (map-elt map -2)))))
|
|
|
|
(ert-deftest test-map-delete-return-value ()
|
|
(let ((ht (make-hash-table)))
|
|
(should (eq (map-delete ht 'a) ht))))
|
|
|
|
(ert-deftest test-map-nested-elt ()
|
|
(let ((vec [a b [c d [e f]]]))
|
|
(should (eq (map-nested-elt vec '(2 2 0)) 'e)))
|
|
(let ((alist '((a . 1)
|
|
(b . ((c . 2)
|
|
(d . 3)
|
|
(e . ((f . 4)
|
|
(g . 5))))))))
|
|
(should (eq (map-nested-elt alist '(b e f))
|
|
4)))
|
|
(let ((ht (make-hash-table)))
|
|
(setf (map-elt ht 'a) 1)
|
|
(setf (map-elt ht 'b) (make-hash-table))
|
|
(setf (map-elt (map-elt ht 'b) 'c) 2)
|
|
(should (eq (map-nested-elt ht '(b c))
|
|
2))))
|
|
|
|
(ert-deftest test-map-nested-elt-default ()
|
|
(let ((vec [a b [c d]]))
|
|
(should (null (map-nested-elt vec '(2 3))))
|
|
(should (null (map-nested-elt vec '(2 1 1))))
|
|
(should (= 4 (map-nested-elt vec '(2 1 1) 4)))))
|
|
|
|
(ert-deftest test-mapp ()
|
|
(should (mapp nil))
|
|
(should (mapp '((a . b) (c . d))))
|
|
(should (mapp '(a b c d)))
|
|
(should (mapp []))
|
|
(should (mapp [1 2 3]))
|
|
(should (mapp (make-hash-table)))
|
|
(should (mapp "hello"))
|
|
(should (not (mapp 1)))
|
|
(should (not (mapp 'hello))))
|
|
|
|
(ert-deftest test-map-keys ()
|
|
(with-maps-do map
|
|
(should (equal (map-keys map) '(0 1 2))))
|
|
(should (null (map-keys nil)))
|
|
(should (null (map-keys []))))
|
|
|
|
(ert-deftest test-map-values ()
|
|
(with-maps-do map
|
|
(should (equal (map-values map) '(3 4 5)))))
|
|
|
|
(ert-deftest test-map-pairs ()
|
|
(with-maps-do map
|
|
(should (equal (map-pairs map) '((0 . 3)
|
|
(1 . 4)
|
|
(2 . 5))))))
|
|
|
|
(ert-deftest test-map-length ()
|
|
(let ((ht (make-hash-table)))
|
|
(puthash 'a 1 ht)
|
|
(puthash 'b 2 ht)
|
|
(puthash 'c 3 ht)
|
|
(puthash 'd 4 ht)
|
|
(should (= 0 (map-length nil)))
|
|
(should (= 0 (map-length [])))
|
|
(should (= 0 (map-length (make-hash-table))))
|
|
(should (= 5 (map-length [0 1 2 3 4])))
|
|
(should (= 2 (map-length '((a . 1) (b . 2)))))
|
|
(should (= 4 (map-length ht)))))
|
|
|
|
(ert-deftest test-map-copy ()
|
|
(with-maps-do map
|
|
(let ((copy (map-copy map)))
|
|
(should (equal (map-keys map) (map-keys copy)))
|
|
(should (equal (map-values map) (map-values copy)))
|
|
(should (not (eq map copy))))))
|
|
|
|
(ert-deftest test-map-apply ()
|
|
(with-maps-do map
|
|
(should (equal (map-apply (lambda (k v) (cons (int-to-string k) v))
|
|
map)
|
|
'(("0" . 3) ("1" . 4) ("2" . 5)))))
|
|
(let ((vec [a b c]))
|
|
(should (equal (map-apply (lambda (k v) (cons (1+ k) v))
|
|
vec)
|
|
'((1 . a)
|
|
(2 . b)
|
|
(3 . c))))))
|
|
|
|
(ert-deftest test-map-keys-apply ()
|
|
(with-maps-do map
|
|
(should (equal (map-keys-apply (lambda (k) (int-to-string k))
|
|
map)
|
|
'("0" "1" "2"))))
|
|
(let ((vec [a b c]))
|
|
(should (equal (map-keys-apply (lambda (k) (1+ k))
|
|
vec)
|
|
'(1 2 3)))))
|
|
|
|
(ert-deftest test-map-values-apply ()
|
|
(with-maps-do map
|
|
(should (equal (map-values-apply (lambda (v) (1+ v))
|
|
map)
|
|
'(4 5 6))))
|
|
(let ((vec [a b c]))
|
|
(should (equal (map-values-apply (lambda (v) (symbol-name v))
|
|
vec)
|
|
'("a" "b" "c")))))
|
|
|
|
(ert-deftest test-map-filter ()
|
|
(with-maps-do map
|
|
(should (equal (map-keys (map-filter (lambda (_k v)
|
|
(<= 4 v))
|
|
map))
|
|
'(1 2)))
|
|
(should (null (map-filter (lambda (k _v)
|
|
(eq 'd k))
|
|
map))))
|
|
(should (null (map-filter (lambda (_k v)
|
|
(eq 3 v))
|
|
[1 2 4 5])))
|
|
(should (equal (map-filter (lambda (k _v)
|
|
(eq 3 k))
|
|
[1 2 4 5])
|
|
'((3 . 5)))))
|
|
|
|
(ert-deftest test-map-remove ()
|
|
(with-maps-do map
|
|
(should (equal (map-keys (map-remove (lambda (_k v)
|
|
(>= v 4))
|
|
map))
|
|
'(0)))
|
|
(should (equal (map-keys (map-remove (lambda (k _v)
|
|
(eq 'd k))
|
|
map))
|
|
(map-keys map))))
|
|
(should (equal (map-remove (lambda (_k v)
|
|
(eq 3 v))
|
|
[1 2 4 5])
|
|
'((0 . 1)
|
|
(1 . 2)
|
|
(2 . 4)
|
|
(3 . 5))))
|
|
(should (null (map-remove (lambda (k _v)
|
|
(>= k 0))
|
|
[1 2 4 5]))))
|
|
|
|
(ert-deftest test-map-empty-p ()
|
|
(should (map-empty-p nil))
|
|
(should (not (map-empty-p '((a . b) (c . d)))))
|
|
(should (map-empty-p []))
|
|
(should (not (map-empty-p [1 2 3])))
|
|
(should (map-empty-p (make-hash-table)))
|
|
(should (not (map-empty-p "hello")))
|
|
(should (map-empty-p "")))
|
|
|
|
(ert-deftest test-map-contains-key ()
|
|
(should (map-contains-key '((a . 1) (b . 2)) 'a))
|
|
(should (not (map-contains-key '((a . 1) (b . 2)) 'c)))
|
|
(should (map-contains-key '(("a" . 1)) "a"))
|
|
(should (not (map-contains-key '(("a" . 1)) "a" #'eq)))
|
|
(should (map-contains-key [a b c] 2))
|
|
(should (not (map-contains-key [a b c] 3))))
|
|
|
|
(ert-deftest test-map-some ()
|
|
(with-maps-do map
|
|
(should (map-some (lambda (k _v)
|
|
(eq 1 k))
|
|
map))
|
|
(should-not (map-some (lambda (k _v)
|
|
(eq 'd k))
|
|
map)))
|
|
(let ((vec [a b c]))
|
|
(should (map-some (lambda (k _v)
|
|
(> k 1))
|
|
vec))
|
|
(should-not (map-some (lambda (k _v)
|
|
(> k 3))
|
|
vec))))
|
|
|
|
(ert-deftest test-map-every-p ()
|
|
(with-maps-do map
|
|
(should (map-every-p (lambda (k _v)
|
|
k)
|
|
map))
|
|
(should (not (map-every-p (lambda (_k _v)
|
|
nil)
|
|
map))))
|
|
(let ((vec [a b c]))
|
|
(should (map-every-p (lambda (k _v)
|
|
(>= k 0))
|
|
vec))
|
|
(should (not (map-every-p (lambda (k _v)
|
|
(> k 3))
|
|
vec)))))
|
|
|
|
(ert-deftest test-map-into ()
|
|
(let* ((alist '((a . 1) (b . 2)))
|
|
(ht (map-into alist 'hash-table)))
|
|
(should (hash-table-p ht))
|
|
(should (equal (map-into (map-into alist 'hash-table) 'list)
|
|
alist))
|
|
(should (listp (map-into ht 'list)))
|
|
(should (equal (map-keys (map-into (map-into ht 'list) 'hash-table))
|
|
(map-keys ht)))
|
|
(should (equal (map-values (map-into (map-into ht 'list) 'hash-table))
|
|
(map-values ht)))
|
|
(should (null (map-into nil 'list)))
|
|
(should (map-empty-p (map-into nil 'hash-table)))
|
|
(should-error (map-into [1 2 3] 'string))))
|
|
|
|
(ert-deftest test-map-let ()
|
|
(map-let (foo bar baz) '((foo . 1) (bar . 2))
|
|
(should (= foo 1))
|
|
(should (= bar 2))
|
|
(should (null baz)))
|
|
(map-let (('foo a)
|
|
('bar b)
|
|
('baz c))
|
|
'((foo . 1) (bar . 2))
|
|
(should (= a 1))
|
|
(should (= b 2))
|
|
(should (null c))))
|
|
|
|
(ert-deftest test-map-merge-with ()
|
|
(should (equal (map-merge-with 'list #'+
|
|
'((1 . 2))
|
|
'((1 . 3) (2 . 4))
|
|
'((1 . 1) (2 . 5) (3 . 0)))
|
|
'((3 . 0) (2 . 9) (1 . 6)))))
|
|
|
|
(provide 'map-tests)
|
|
;;; map-tests.el ends here
|