aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorEric S. Raymond2026-02-25 17:23:46 -0500
committerEric S. Raymond2026-02-25 17:23:46 -0500
commit7a93a7b3345f7ae4e8f487b562b19a4b5fed8496 (patch)
tree84b6365646c8a0969dcbbdf85ba1851b2fd003d6 /test/src
parentfc7339c46dc87d5d7051f976206bb5c4d9efdfb8 (diff)
downloademacs-7a93a7b3345f7ae4e8f487b562b19a4b5fed8496.tar.gz
emacs-7a93a7b3345f7ae4e8f487b562b19a4b5fed8496.zip
Category/charset/coding + char-table tests.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/category-tests.el71
-rw-r--r--test/src/charset-tests.el51
-rw-r--r--test/src/chartab-tests.el9
-rw-r--r--test/src/coding-tests.el42
4 files changed, 173 insertions, 0 deletions
diff --git a/test/src/category-tests.el b/test/src/category-tests.el
new file mode 100644
index 00000000000..e66d7d40fe6
--- /dev/null
+++ b/test/src/category-tests.el
@@ -0,0 +1,71 @@
1;;; category-tests.el --- Tests for category.c -*- lexical-binding: t -*-
2
3;; Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest category-tests-category-table ()
25 (let ((table (make-category-table)))
26 (should (category-table-p table))
27 (should (category-table-p (standard-category-table)))
28 (should-not (category-table-p (make-char-table 'foo)))))
29
30(ert-deftest category-tests-define-category-docstring ()
31 (let ((table (make-category-table)))
32 (define-category ?a "Alpha category." table)
33 (should (equal (category-docstring ?a table) "Alpha category."))
34 (should-error (define-category ?a "Duplicate." table))))
35
36(ert-deftest category-tests-set-category-table ()
37 (let ((table (make-category-table)))
38 (with-temp-buffer
39 (should (eq (set-category-table table) table))
40 (should (eq (category-table) table)))))
41
42(ert-deftest category-tests-category-set-mnemonics ()
43 (let ((set (make-category-set "aZ")))
44 (should (equal (category-set-mnemonics set) "Za")))
45 (let ((set (make-category-set "")))
46 (should (equal (category-set-mnemonics set) ""))))
47
48(ert-deftest category-tests-char-category-set ()
49 (let ((table (make-category-table)))
50 (define-category ?a "Alpha category." table)
51 (modify-category-entry ?x ?a table)
52 (with-temp-buffer
53 (set-category-table table)
54 (let ((mnemonics (category-set-mnemonics (char-category-set ?x))))
55 (should (string-match-p "a" mnemonics))))))
56
57(ert-deftest category-tests-copy-category-table ()
58 (let ((table (make-category-table)))
59 (define-category ?a "Alpha category." table)
60 (modify-category-entry ?x ?a table)
61 (let ((copy (copy-category-table table)))
62 (modify-category-entry ?x ?a table t)
63 (with-temp-buffer
64 (set-category-table copy)
65 (should (equal (category-set-mnemonics (char-category-set ?x)) "a")))
66 (with-temp-buffer
67 (set-category-table table)
68 (should (equal (category-set-mnemonics (char-category-set ?x)) ""))))))
69
70(provide 'category-tests)
71;;; category-tests.el ends here
diff --git a/test/src/charset-tests.el b/test/src/charset-tests.el
index 7545a907f5f..f0097cdaa90 100644
--- a/test/src/charset-tests.el
+++ b/test/src/charset-tests.el
@@ -25,6 +25,57 @@
25 "Test `decode-char'." 25 "Test `decode-char'."
26 (should-error (decode-char 'ascii 0.5))) 26 (should-error (decode-char 'ascii 0.5)))
27 27
28(ert-deftest charset-tests-charsetp ()
29 (should (charsetp 'ascii))
30 (should (charsetp 'unicode))
31 (should-not (charsetp 'charset-tests-no-such-charset)))
32
33(ert-deftest charset-tests-charset-id-internal ()
34 (let ((id (charset-id-internal 'ascii)))
35 (should (integerp id))
36 (should (<= 0 id))))
37
38(ert-deftest charset-tests-charset-plist ()
39 (let ((plist (charset-plist 'ascii)))
40 (should (listp plist))
41 (should (stringp (plist-get plist :short-name)))))
42
43(ert-deftest charset-tests-charset-priority-list ()
44 (let ((list (charset-priority-list)))
45 (should (listp list))
46 (should (consp list))
47 (should (memq 'ascii list))
48 (dolist (cs list)
49 (should (charsetp cs))))
50 (let ((highest (charset-priority-list t)))
51 (should (symbolp highest))
52 (should (charsetp highest))))
53
54(ert-deftest charset-tests-charset-after ()
55 (with-temp-buffer
56 (insert "a")
57 (goto-char (point-min))
58 (should (eq (charset-after) 'ascii))
59 (should-not (charset-after (1+ (point-max))))))
60
61(ert-deftest charset-tests-find-charset-string ()
62 (let ((charsets (find-charset-string "abc")))
63 (should (memq 'ascii charsets))
64 (dolist (cs charsets)
65 (should (charsetp cs))))
66 (let ((charsets (find-charset-string "あ")))
67 (should (consp charsets))
68 (dolist (cs charsets)
69 (should (charsetp cs)))))
70
71(ert-deftest charset-tests-find-charset-region ()
72 (with-temp-buffer
73 (insert "abc")
74 (let ((charsets (find-charset-region (point-min) (point-max))))
75 (should (memq 'ascii charsets))
76 (dolist (cs charsets)
77 (should (charsetp cs))))))
78
28(provide 'charset-tests) 79(provide 'charset-tests)
29 80
30;;; charset-tests.el ends here 81;;; charset-tests.el ends here
diff --git a/test/src/chartab-tests.el b/test/src/chartab-tests.el
index 0f2e65b89a0..24b0f6d12d4 100644
--- a/test/src/chartab-tests.el
+++ b/test/src/chartab-tests.el
@@ -69,5 +69,14 @@
69 (set-char-table-extra-slot tbl 1 'bar) 69 (set-char-table-extra-slot tbl 1 'bar)
70 (should (eq (char-table-extra-slot tbl 1) 'bar)))) 70 (should (eq (char-table-extra-slot tbl 1) 'bar))))
71 71
72(ert-deftest chartab-test-char-table-range ()
73 (let ((tbl (make-char-table nil nil)))
74 (set-char-table-range tbl '(?a . ?z) 'letters)
75 (should (eq (char-table-range tbl ?a) 'letters))
76 (should (eq (char-table-range tbl '(?a . ?z)) 'letters))
77 (should-not (char-table-range tbl ?0))
78 (set-char-table-range tbl nil 'default)
79 (should (eq (char-table-range tbl nil) 'default))))
80
72(provide 'chartab-tests) 81(provide 'chartab-tests)
73;;; chartab-tests.el ends here 82;;; chartab-tests.el ends here
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index dc1abec2d58..4529002ad3b 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -421,6 +421,48 @@
421 (should-not (eq (encode-coding-string s coding nil) s)) 421 (should-not (eq (encode-coding-string s coding nil) s))
422 (should (eq (encode-coding-string s coding t) s)))))) 422 (should (eq (encode-coding-string s coding t) s))))))
423 423
424(ert-deftest coding-tests-coding-system-p ()
425 (should (coding-system-p nil))
426 (should (coding-system-p 'utf-8))
427 (should-not (coding-system-p 'coding-tests-no-such-system)))
428
429(ert-deftest coding-tests-check-coding-system ()
430 (should (eq (check-coding-system 'utf-8) 'utf-8))
431 (should (eq (check-coding-system nil) nil))
432 (should-error (check-coding-system 'coding-tests-no-such-system)
433 :type 'coding-system-error))
434
435(ert-deftest coding-tests-coding-system-priority-list ()
436 (let ((list (coding-system-priority-list)))
437 (should (listp list))
438 (should (consp list))
439 (dolist (cs list)
440 (should (coding-system-p cs))))
441 (let ((highest (coding-system-priority-list t)))
442 (should (symbolp highest))
443 (should (coding-system-p highest))))
444
445(ert-deftest coding-tests-coding-system-aliases ()
446 (let ((aliases (coding-system-aliases 'utf-8)))
447 (should (listp aliases))
448 (should (memq 'utf-8 aliases))))
449
450(ert-deftest coding-tests-coding-system-plist ()
451 (let ((plist (coding-system-plist 'utf-8)))
452 (should (listp plist))
453 (should (plist-member plist :mnemonic))))
454
455(ert-deftest coding-tests-coding-system-put ()
456 (let* ((cs 'utf-8)
457 (mnemonic (plist-get (coding-system-plist cs) :mnemonic)))
458 (coding-system-put cs :mnemonic mnemonic)
459 (should (eq (plist-get (coding-system-plist cs) :mnemonic) mnemonic))))
460
461(ert-deftest coding-tests-coding-system-eol-type ()
462 (let ((eol (coding-system-eol-type 'utf-8-unix)))
463 (should (integerp eol))
464 (should (memq eol '(0 1 2)))))
465
424 466
425(ert-deftest coding-check-coding-systems-region () 467(ert-deftest coding-check-coding-systems-region ()
426 (should (equal (check-coding-systems-region "aå" nil '(utf-8)) 468 (should (equal (check-coding-systems-region "aå" nil '(utf-8))