aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/category-tests.el
blob: e66d7d40fe64f303ede6332c272f470dd2ed7185 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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