unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 403b355bb6ec78ca13d36e8ab0bc3203333457b5 5240 bytes (raw)
name: test/lisp/international/mule-util-tests.el 	 # note: path name is non-authoritative(*)

  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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
 
;;; mule-util-tests --- tests for international/mule-util.el

;; Copyright (C) 2002-2020 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/>.

;;; Commentary:

;;; Code:

(require 'ert)
(require 'mule-util)

(defconst mule-util-test-truncate-data
  '((("" 0) . "")
    (("x" 1) . "x")
    (("xy" 1) . "x")
    (("xy" 2 1) . "y")
    (("xy" 0) . "")
    (("xy" 3) . "xy")
    (("中" 0) . "")
    (("中" 1) . "")
    (("中" 2) . "中")
    (("中" 1 nil ? ) . " ")
    (("中文" 3 1 ? ) . "  ")
    (("x中x" 2) . "x")
    (("x中x" 3) . "x中")
    (("x中x" 3) . "x中")
    (("x中x" 4 1) . "中x")
    (("kor한e글an" 8 1 ? ) . "or한e글")
    (("kor한e글an" 7 2 ? ) . "r한e ")
    (("" 0 nil nil "...") . "")
    (("x" 3 nil nil "...") . "x")
    (("中" 3 nil nil "...") . "中")
    (("foo" 3 nil nil "...") . "foo")
    (("foo" 2 nil nil "...") . "fo") ;; XEmacs failure?
    (("foobar" 6 0 nil "...") . "foobar")
    (("foobarbaz" 6 nil nil "...") . "foo...")
    (("foobarbaz" 7 2 nil "...") . "ob...")
    (("foobarbaz" 9 3 nil "...") . "barbaz")
    (("こhんeにlちlはo" 15 1 ?  t) . " hんeにlちlはo")
    (("こhんeにlちlはo" 14 1 ?  t) . " hんeにlち...")
    (("x" 3 nil nil "粵語") . "x")
    (("中" 2 nil nil "粵語") . "中")
    (("中" 1 nil ?x "粵語") . "x") ;; XEmacs error
    (("中文" 3 nil ?  "粵語") . "中 ") ;; XEmacs error
    (("foobarbaz" 4 nil nil  "粵語") . "粵語")
    (("foobarbaz" 5 nil nil  "粵語") . "f粵語")
    (("foobarbaz" 6 nil nil  "粵語") . "fo粵語")
    (("foobarbaz" 8 3 nil "粵語") . "b粵語")
    (("こhんeにlちlはo" 14 4 ?x "日本語") . "xeに日本語")
    (("こhんeにlちlはo" 13 4 ?x "日本語") . "xex日本語")
    )
  "Test data for `truncate-string-to-width'.")

(defun mule-util-test-truncate-create (n)
  "Create a test for element N of the `mule-util-test-truncate-data' constant."
  (let ((testname (intern (format "mule-util-test-truncate-%.2d" n)))
        (testdoc (format "Test element %d of `mule-util-test-truncate-data'."
                         n))
        (testdata (nth n mule-util-test-truncate-data)))
    (eval
     `(ert-deftest ,testname ()
        ,testdoc
        (should (equal (apply 'truncate-string-to-width ',(car testdata))
                              ,(cdr testdata)))))))

(dotimes (i (length mule-util-test-truncate-data))
  (mule-util-test-truncate-create i))

(ert-deftest truncate-string-left ()
  (let ((truncate-string-ellipsis "..."))
    (should (equal (truncate-string-left "ahojky jojky mojky" 10)
                   "...y mojky"))
    (should (equal (truncate-string-left "jojky mojky" 10)
                   "...y mojky"))
    (should (equal (truncate-string-left "jojky" 10)
                   "jojky"))
    (should (equal (truncate-string-left "jojky" 3)
                   "jky"))
    (should (equal (truncate-string-left "我的老田野" 10)
                   "我的老田野"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 10)
                   "...食我叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 3)
                   "叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,jojky" 10)
                   "...,jojky")))
  (let ((truncate-string-ellipsis "......"))
    (should (equal (truncate-string-left "ahojky jojky mojky" 10)
                   "......ojky"))
    (should (equal (truncate-string-left "jojky" 3)
                   "jky"))
    (should (equal (truncate-string-left "我的老田野" 10)
                   "我的老田野"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 10)
                   "......我叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 3)
                   "叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,jojky" 10)
                   "......ojky")))
  (let ((truncate-string-ellipsis "…"))
    (should (equal (truncate-string-left "ahojky jojky mojky" 10)
                   "…jky mojky"))
    (should (equal (truncate-string-left "jojky" 3)
                   "…ky"))
    (should (equal (truncate-string-left "我的老田野" 10)
                   "我的老田野"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 10)
                   "…甭食我叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,甭食我叔" 3)
                   "…叔"))
    (should (equal (truncate-string-left "碩鼠碩鼠,jojky" 10)
                   "…鼠,jojky"))))

;;; mule-util-tests.el ends here

debug log:

solving 403b355bb6 ...
found 403b355bb6 in https://yhetil.org/emacs-devel/87k12ia05d.fsf@gmail.com/
found c571782d63 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 c571782d6351da2b6e80dcfd7742f290e16336d4	test/lisp/international/mule-util-tests.el

applying [1/1] https://yhetil.org/emacs-devel/87k12ia05d.fsf@gmail.com/
diff --git a/test/lisp/international/mule-util-tests.el b/test/lisp/international/mule-util-tests.el
index c571782d63..403b355bb6 100644

Checking patch test/lisp/international/mule-util-tests.el...
Applied patch test/lisp/international/mule-util-tests.el cleanly.

index at:
100644 403b355bb6ec78ca13d36e8ab0bc3203333457b5	test/lisp/international/mule-util-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).