aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorVincent Belaïche2016-07-28 18:12:50 +0200
committerVincent Belaïche2016-07-28 18:12:50 +0200
commit90ab699c4f281d0c9a9b71f3eb4c8493d00fcf4f (patch)
treedf3235d89ee8e4d32571b8a8521f75f7576913c2 /test/src
parent41b28dea8587c13b0bc59c1ec70b65afab3aeeca (diff)
parentec359399a47f852b4d022a30245449438e349193 (diff)
downloademacs-90ab699c4f281d0c9a9b71f3eb4c8493d00fcf4f.tar.gz
emacs-90ab699c4f281d0c9a9b71f3eb4c8493d00fcf4f.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'test/src')
-rw-r--r--test/src/callproc-tests.el39
-rw-r--r--test/src/chartab-tests.el51
-rw-r--r--test/src/editfns-tests.el136
-rw-r--r--test/src/fns-tests.el10
-rw-r--r--test/src/regex-tests.el92
5 files changed, 328 insertions, 0 deletions
diff --git a/test/src/callproc-tests.el b/test/src/callproc-tests.el
new file mode 100644
index 00000000000..46541aba78c
--- /dev/null
+++ b/test/src/callproc-tests.el
@@ -0,0 +1,39 @@
1;;; callproc-tests.el --- callproc.c tests -*- lexical-binding: t -*-
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(eval-when-compile (require 'cl-lib))
24
25(ert-deftest initial-environment-preserved ()
26 "Check that `initial-environment' is not modified by Emacs (Bug #10980)."
27 (skip-unless (eq system-type 'windows-nt))
28 (cl-destructuring-bind (initial-shell shell)
29 (with-temp-buffer
30 (let ((process-environment (cons "SHELL" process-environment)))
31 (call-process (expand-file-name invocation-name invocation-directory)
32 nil t nil
33 "--batch" "-Q" "--eval"
34 (prin1-to-string
35 '(progn (prin1 (getenv-internal "SHELL" initial-environment))
36 (prin1 (getenv-internal "SHELL"))))))
37 (split-string-and-unquote (buffer-string)))
38 (should (equal initial-shell "nil"))
39 (should-not (equal initial-shell shell))))
diff --git a/test/src/chartab-tests.el b/test/src/chartab-tests.el
new file mode 100644
index 00000000000..016ddcdde61
--- /dev/null
+++ b/test/src/chartab-tests.el
@@ -0,0 +1,51 @@
1;;; chartab-tests.el --- Tests for char-tab.c
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Author: Eli Zaretskii <eliz@gnu.org>
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(defun chartab-set-and-test (rng)
25 (let ((tbl (make-char-table nil nil))
26 (from (car rng))
27 (to (cdr rng)))
28 (set-char-table-range tbl rng t)
29 (should (eq (aref tbl from) t))
30 (should (eq (aref tbl to) t))
31 (should (eq (aref tbl (/ (+ from to) 2)) t))
32 (when (< to (max-char))
33 (should-not (eq (aref tbl (1+ to)) t)))
34 (when (> from 0)
35 (should-not (eq (aref tbl (1- from)) t)))))
36
37(ert-deftest chartab-test-range-setting ()
38 (mapc (lambda (elt)
39 (chartab-set-and-test elt))
40 '((0 . 127)
41 (128 . 256)
42 (#x1000 . #x1fff)
43 (#x1001 . #x2000)
44 (#x10000 . #x20000)
45 (#x10001 . #x1ffff)
46 (#x20000 . #x30000)
47 (#xe0e00 . #xe0ef6)
48 )))
49
50(provide 'chartab-tests)
51;;; chartab-tests.el ends here
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
new file mode 100644
index 00000000000..2f90d1e7495
--- /dev/null
+++ b/test/src/editfns-tests.el
@@ -0,0 +1,136 @@
1;;; editfns-tests.el -- tests for editfns.c
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest format-properties ()
25 ;; Bug #23730
26 (should (ert-equal-including-properties
27 (format (propertize "%d" 'face '(:background "red")) 1)
28 #("1" 0 1 (face (:background "red")))))
29 (should (ert-equal-including-properties
30 (format (propertize "%2d" 'face '(:background "red")) 1)
31 #(" 1" 0 2 (face (:background "red")))))
32 (should (ert-equal-including-properties
33 (format (propertize "%02d" 'face '(:background "red")) 1)
34 #("01" 0 2 (face (:background "red")))))
35 (should (ert-equal-including-properties
36 (format (concat (propertize "%2d" 'x 'X)
37 (propertize "a" 'a 'A)
38 (propertize "b" 'b 'B))
39 1)
40 #(" 1ab" 0 2 (x X) 2 3 (a A) 3 4 (b B))))
41
42 ;; Bug #5306
43 (should (ert-equal-including-properties
44 (format "%.10s"
45 (concat "1234567890aaaa"
46 (propertize "12345678901234567890" 'xxx 25)))
47 "1234567890"))
48 (should (ert-equal-including-properties
49 (format "%.10s"
50 (concat "123456789"
51 (propertize "12345678901234567890" 'xxx 25)))
52 #("1234567891" 9 10 (xxx 25))))
53
54 ;; Bug #23859
55 (should (ert-equal-including-properties
56 (format "%4s" (propertize "hi" 'face 'bold))
57 #(" hi" 2 4 (face bold))))
58
59 ;; Bug #23897
60 (should (ert-equal-including-properties
61 (format "%s" (concat (propertize "01234" 'face 'bold) "56789"))
62 #("0123456789" 0 5 (face bold))))
63 (should (ert-equal-including-properties
64 (format "%s" (concat (propertize "01" 'face 'bold)
65 (propertize "23" 'face 'underline)
66 "45"))
67 #("012345" 0 2 (face bold) 2 4 (face underline))))
68 ;; The last property range is extended to include padding on the
69 ;; right, but the first range is not extended to the left to include
70 ;; padding on the left!
71 (should (ert-equal-including-properties
72 (format "%12s" (concat (propertize "01234" 'face 'bold) "56789"))
73 #(" 0123456789" 2 7 (face bold))))
74 (should (ert-equal-including-properties
75 (format "%-12s" (concat (propertize "01234" 'face 'bold) "56789"))
76 #("0123456789 " 0 5 (face bold))))
77 (should (ert-equal-including-properties
78 (format "%10s" (concat (propertize "01" 'face 'bold)
79 (propertize "23" 'face 'underline)
80 "45"))
81 #(" 012345" 4 6 (face bold) 6 8 (face underline))))
82 (should (ert-equal-including-properties
83 (format "%-10s" (concat (propertize "01" 'face 'bold)
84 (propertize "23" 'face 'underline)
85 "45"))
86 #("012345 " 0 2 (face bold) 2 4 (face underline))))
87 (should (ert-equal-including-properties
88 (format "%-10s" (concat (propertize "01" 'face 'bold)
89 (propertize "23" 'face 'underline)
90 (propertize "45" 'face 'italic)))
91 #("012345 " 0 2 (face bold) 2 4 (face underline) 4 10 (face italic)))))
92
93;; Tests for bug#5131.
94(defun transpose-test-reverse-word (start end)
95 "Reverse characters in a word by transposing pairs of characters."
96 (let ((begm (make-marker))
97 (endm (make-marker)))
98 (set-marker begm start)
99 (set-marker endm end)
100 (while (> endm begm)
101 (progn (transpose-regions begm (1+ begm) endm (1+ endm) t)
102 (set-marker begm (1+ begm))
103 (set-marker endm (1- endm))))))
104
105(defun transpose-test-get-byte-positions (len)
106 "Validate character position to byte position translation."
107 (let ((bytes '()))
108 (dotimes (pos len)
109 (setq bytes (add-to-list 'bytes (position-bytes (1+ pos)) t)))
110 bytes))
111
112(ert-deftest transpose-ascii-regions-test ()
113 (with-temp-buffer
114 (erase-buffer)
115 (insert "abcd")
116 (transpose-test-reverse-word 1 4)
117 (should (string= (buffer-string) "dcba"))
118 (should (equal (transpose-test-get-byte-positions 5) '(1 2 3 4 5)))))
119
120(ert-deftest transpose-nonascii-regions-test-1 ()
121 (with-temp-buffer
122 (erase-buffer)
123 (insert "÷bcd")
124 (transpose-test-reverse-word 1 4)
125 (should (string= (buffer-string) "dcb÷"))
126 (should (equal (transpose-test-get-byte-positions 5) '(1 2 3 4 6)))))
127
128(ert-deftest transpose-nonascii-regions-test-2 ()
129 (with-temp-buffer
130 (erase-buffer)
131 (insert "÷ab\"äé")
132 (transpose-test-reverse-word 1 6)
133 (should (string= (buffer-string) "éä\"ba÷"))
134 (should (equal (transpose-test-get-byte-positions 7) '(1 3 5 6 7 8 10)))))
135
136;;; editfns-tests.el ends here
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 848589692ea..c533bad3cdc 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -235,3 +235,13 @@
235 (backward-delete-char 1) 235 (backward-delete-char 1)
236 (buffer-hash)) 236 (buffer-hash))
237 (sha1 "foo")))) 237 (sha1 "foo"))))
238
239(ert-deftest fns-tests-mapcan ()
240 (should-error (mapcan))
241 (should-error (mapcan #'identity))
242 (should-error (mapcan #'identity (make-char-table 'foo)))
243 (should (equal (mapcan #'list '(1 2 3)) '(1 2 3)))
244 ;; `mapcan' is destructive
245 (let ((data '((foo) (bar))))
246 (should (equal (mapcan #'identity data) '(foo bar)))
247 (should (equal data '((foo bar) (bar))))))
diff --git a/test/src/regex-tests.el b/test/src/regex-tests.el
new file mode 100644
index 00000000000..00165ab0512
--- /dev/null
+++ b/test/src/regex-tests.el
@@ -0,0 +1,92 @@
1;;; regex-tests.el --- tests for regex.c functions -*- lexical-binding: t -*-
2
3;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest regex-word-cc-fallback-test ()
25 "Test that ‘[[:cc:]]*x’ matches ‘x’ (bug#24020).
26
27Test that a regex of the form \"[[:cc:]]*x\" where CC is
28a character class which matches a multibyte character X, matches
29string \"x\".
30
31For example, ‘[[:word:]]*\u2620’ regex (note: \u2620 is a word
32character) must match a string \"\u2420\"."
33 (dolist (class '("[[:word:]]" "\\sw"))
34 (dolist (repeat '("*" "+"))
35 (dolist (suffix '("" "b" "bar" "\u2620"))
36 (dolist (string '("" "foo"))
37 (when (not (and (string-equal repeat "+")
38 (string-equal string "")))
39 (should (string-match (concat "^" class repeat suffix "$")
40 (concat string suffix)))))))))
41
42(defun regex--test-cc (name matching not-matching)
43 (should (string-match-p (concat "^[[:" name ":]]*$") matching))
44 (should (string-match-p (concat "^[[:" name ":]]*?\u2622$")
45 (concat matching "\u2622")))
46 (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching))
47 (should (string-match-p (concat "^[^[:" name ":]]*\u2622$")
48 (concat not-matching "\u2622")))
49 (with-temp-buffer
50 (insert matching)
51 (let ((p (point)))
52 (insert not-matching)
53 (goto-char (point-min))
54 (skip-chars-forward (concat "[:" name ":]"))
55 (should (equal (point) p))
56 (skip-chars-forward (concat "^[:" name ":]"))
57 (should (equal (point) (point-max)))
58 (goto-char (point-min))
59 (skip-chars-forward (concat "[:" name ":]\u2622"))
60 (should (or (equal (point) p) (equal (point) (1+ p)))))))
61
62(ert-deftest regex-character-classes ()
63 "Perform sanity test of regexes using character classes.
64
65Go over all the supported character classes and test whether the
66classes and their inversions match what they are supposed to
67match. The test is done using `string-match-p' as well as
68`skip-chars-forward'."
69 (let (case-fold-search)
70 (regex--test-cc "alnum" "abcABC012łąka" "-, \t\n")
71 (regex--test-cc "alpha" "abcABCłąka" "-,012 \t\n")
72 (regex--test-cc "digit" "012" "abcABCłąka-, \t\n")
73 (regex--test-cc "xdigit" "0123aBc" "łąk-, \t\n")
74 (regex--test-cc "upper" "ABCŁĄKA" "abc012-, \t\n")
75 (regex--test-cc "lower" "abcłąka" "ABC012-, \t\n")
76
77 (regex--test-cc "word" "abcABC012\u2620" "-, \t\n")
78
79 (regex--test-cc "punct" ".,-" "abcABC012\u2620 \t\n")
80 (regex--test-cc "cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
81 (regex--test-cc "graph" "abcłąka\u2620-," " \t\n\1")
82 (regex--test-cc "print" "abcłąka\u2620-, " "\t\n\1")
83
84 (regex--test-cc "space" " \t\n\u2001" "abcABCł0123")
85 (regex--test-cc "blank" " \t" "\n\u2001")
86
87 (regex--test-cc "ascii" "abcABC012 \t\n\1" "łą\u2620")
88 (regex--test-cc "nonascii" "łą\u2622" "abcABC012 \t\n\1")
89 (regex--test-cc "unibyte" "abcABC012 \t\n\1" "łą\u2622")
90 (regex--test-cc "multibyte" "łą\u2622" "abcABC012 \t\n\1")))
91
92;;; regex-tests.el ends here