mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-03-13 02:12:18 -07:00
Category/charset/coding + char-table tests.
This commit is contained in:
parent
fc7339c46d
commit
7a93a7b334
4 changed files with 173 additions and 0 deletions
71
test/src/category-tests.el
Normal file
71
test/src/category-tests.el
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
;;; category-tests.el --- Tests for category.c -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
|
||||
;; 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
|
||||
(ert-deftest category-tests-category-table ()
|
||||
(let ((table (make-category-table)))
|
||||
(should (category-table-p table))
|
||||
(should (category-table-p (standard-category-table)))
|
||||
(should-not (category-table-p (make-char-table 'foo)))))
|
||||
|
||||
(ert-deftest category-tests-define-category-docstring ()
|
||||
(let ((table (make-category-table)))
|
||||
(define-category ?a "Alpha category." table)
|
||||
(should (equal (category-docstring ?a table) "Alpha category."))
|
||||
(should-error (define-category ?a "Duplicate." table))))
|
||||
|
||||
(ert-deftest category-tests-set-category-table ()
|
||||
(let ((table (make-category-table)))
|
||||
(with-temp-buffer
|
||||
(should (eq (set-category-table table) table))
|
||||
(should (eq (category-table) table)))))
|
||||
|
||||
(ert-deftest category-tests-category-set-mnemonics ()
|
||||
(let ((set (make-category-set "aZ")))
|
||||
(should (equal (category-set-mnemonics set) "Za")))
|
||||
(let ((set (make-category-set "")))
|
||||
(should (equal (category-set-mnemonics set) ""))))
|
||||
|
||||
(ert-deftest category-tests-char-category-set ()
|
||||
(let ((table (make-category-table)))
|
||||
(define-category ?a "Alpha category." table)
|
||||
(modify-category-entry ?x ?a table)
|
||||
(with-temp-buffer
|
||||
(set-category-table table)
|
||||
(let ((mnemonics (category-set-mnemonics (char-category-set ?x))))
|
||||
(should (string-match-p "a" mnemonics))))))
|
||||
|
||||
(ert-deftest category-tests-copy-category-table ()
|
||||
(let ((table (make-category-table)))
|
||||
(define-category ?a "Alpha category." table)
|
||||
(modify-category-entry ?x ?a table)
|
||||
(let ((copy (copy-category-table table)))
|
||||
(modify-category-entry ?x ?a table t)
|
||||
(with-temp-buffer
|
||||
(set-category-table copy)
|
||||
(should (equal (category-set-mnemonics (char-category-set ?x)) "a")))
|
||||
(with-temp-buffer
|
||||
(set-category-table table)
|
||||
(should (equal (category-set-mnemonics (char-category-set ?x)) ""))))))
|
||||
|
||||
(provide 'category-tests)
|
||||
;;; category-tests.el ends here
|
||||
|
|
@ -25,6 +25,57 @@
|
|||
"Test `decode-char'."
|
||||
(should-error (decode-char 'ascii 0.5)))
|
||||
|
||||
(ert-deftest charset-tests-charsetp ()
|
||||
(should (charsetp 'ascii))
|
||||
(should (charsetp 'unicode))
|
||||
(should-not (charsetp 'charset-tests-no-such-charset)))
|
||||
|
||||
(ert-deftest charset-tests-charset-id-internal ()
|
||||
(let ((id (charset-id-internal 'ascii)))
|
||||
(should (integerp id))
|
||||
(should (<= 0 id))))
|
||||
|
||||
(ert-deftest charset-tests-charset-plist ()
|
||||
(let ((plist (charset-plist 'ascii)))
|
||||
(should (listp plist))
|
||||
(should (stringp (plist-get plist :short-name)))))
|
||||
|
||||
(ert-deftest charset-tests-charset-priority-list ()
|
||||
(let ((list (charset-priority-list)))
|
||||
(should (listp list))
|
||||
(should (consp list))
|
||||
(should (memq 'ascii list))
|
||||
(dolist (cs list)
|
||||
(should (charsetp cs))))
|
||||
(let ((highest (charset-priority-list t)))
|
||||
(should (symbolp highest))
|
||||
(should (charsetp highest))))
|
||||
|
||||
(ert-deftest charset-tests-charset-after ()
|
||||
(with-temp-buffer
|
||||
(insert "a")
|
||||
(goto-char (point-min))
|
||||
(should (eq (charset-after) 'ascii))
|
||||
(should-not (charset-after (1+ (point-max))))))
|
||||
|
||||
(ert-deftest charset-tests-find-charset-string ()
|
||||
(let ((charsets (find-charset-string "abc")))
|
||||
(should (memq 'ascii charsets))
|
||||
(dolist (cs charsets)
|
||||
(should (charsetp cs))))
|
||||
(let ((charsets (find-charset-string "あ")))
|
||||
(should (consp charsets))
|
||||
(dolist (cs charsets)
|
||||
(should (charsetp cs)))))
|
||||
|
||||
(ert-deftest charset-tests-find-charset-region ()
|
||||
(with-temp-buffer
|
||||
(insert "abc")
|
||||
(let ((charsets (find-charset-region (point-min) (point-max))))
|
||||
(should (memq 'ascii charsets))
|
||||
(dolist (cs charsets)
|
||||
(should (charsetp cs))))))
|
||||
|
||||
(provide 'charset-tests)
|
||||
|
||||
;;; charset-tests.el ends here
|
||||
|
|
|
|||
|
|
@ -69,5 +69,14 @@
|
|||
(set-char-table-extra-slot tbl 1 'bar)
|
||||
(should (eq (char-table-extra-slot tbl 1) 'bar))))
|
||||
|
||||
(ert-deftest chartab-test-char-table-range ()
|
||||
(let ((tbl (make-char-table nil nil)))
|
||||
(set-char-table-range tbl '(?a . ?z) 'letters)
|
||||
(should (eq (char-table-range tbl ?a) 'letters))
|
||||
(should (eq (char-table-range tbl '(?a . ?z)) 'letters))
|
||||
(should-not (char-table-range tbl ?0))
|
||||
(set-char-table-range tbl nil 'default)
|
||||
(should (eq (char-table-range tbl nil) 'default))))
|
||||
|
||||
(provide 'chartab-tests)
|
||||
;;; chartab-tests.el ends here
|
||||
|
|
|
|||
|
|
@ -421,6 +421,48 @@
|
|||
(should-not (eq (encode-coding-string s coding nil) s))
|
||||
(should (eq (encode-coding-string s coding t) s))))))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-p ()
|
||||
(should (coding-system-p nil))
|
||||
(should (coding-system-p 'utf-8))
|
||||
(should-not (coding-system-p 'coding-tests-no-such-system)))
|
||||
|
||||
(ert-deftest coding-tests-check-coding-system ()
|
||||
(should (eq (check-coding-system 'utf-8) 'utf-8))
|
||||
(should (eq (check-coding-system nil) nil))
|
||||
(should-error (check-coding-system 'coding-tests-no-such-system)
|
||||
:type 'coding-system-error))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-priority-list ()
|
||||
(let ((list (coding-system-priority-list)))
|
||||
(should (listp list))
|
||||
(should (consp list))
|
||||
(dolist (cs list)
|
||||
(should (coding-system-p cs))))
|
||||
(let ((highest (coding-system-priority-list t)))
|
||||
(should (symbolp highest))
|
||||
(should (coding-system-p highest))))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-aliases ()
|
||||
(let ((aliases (coding-system-aliases 'utf-8)))
|
||||
(should (listp aliases))
|
||||
(should (memq 'utf-8 aliases))))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-plist ()
|
||||
(let ((plist (coding-system-plist 'utf-8)))
|
||||
(should (listp plist))
|
||||
(should (plist-member plist :mnemonic))))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-put ()
|
||||
(let* ((cs 'utf-8)
|
||||
(mnemonic (plist-get (coding-system-plist cs) :mnemonic)))
|
||||
(coding-system-put cs :mnemonic mnemonic)
|
||||
(should (eq (plist-get (coding-system-plist cs) :mnemonic) mnemonic))))
|
||||
|
||||
(ert-deftest coding-tests-coding-system-eol-type ()
|
||||
(let ((eol (coding-system-eol-type 'utf-8-unix)))
|
||||
(should (integerp eol))
|
||||
(should (memq eol '(0 1 2)))))
|
||||
|
||||
|
||||
(ert-deftest coding-check-coding-systems-region ()
|
||||
(should (equal (check-coding-systems-region "aå" nil '(utf-8))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue