diff options
| author | Glenn Morris | 2013-08-04 18:32:00 -0700 |
|---|---|---|
| committer | Glenn Morris | 2013-08-04 18:32:00 -0700 |
| commit | 3e2cd454fdc04a1afefa23cdfe241c11862eaa8d (patch) | |
| tree | 59cfe8cfbfc47f11f238ed488964442ab3e9ee7a | |
| parent | d5671a82b8b78b5fd8d83cfc15642d2c0eff6de2 (diff) | |
| download | emacs-3e2cd454fdc04a1afefa23cdfe241c11862eaa8d.tar.gz emacs-3e2cd454fdc04a1afefa23cdfe241c11862eaa8d.zip | |
Extract truncate-string-to-width tests to a separate file
* test/automated/mule-util.el: New file, with tests extracted from
lisp/international/mule-util.el.
Copyright years based on when the original test-suite comment was
added to lisp/international/mule-util.el (in 2002).
* lisp/international/mule-util.el: Extract comment test-suite out to
separate file.
| -rw-r--r-- | lisp/international/mule-util.el | 53 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/automated/mule-util.el | 84 |
3 files changed, 89 insertions, 53 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index 15a7dc10f65..21e09593187 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -125,59 +125,6 @@ defaults to \"...\"." | |||
| 125 | (concat head-padding (substring str from-idx idx) | 125 | (concat head-padding (substring str from-idx idx) |
| 126 | tail-padding ellipsis)))) | 126 | tail-padding ellipsis)))) |
| 127 | 127 | ||
| 128 | ;;; Test suite for truncate-string-to-width | ||
| 129 | ;; (dolist (test '((("" 0) . "") | ||
| 130 | ;; (("x" 1) . "x") | ||
| 131 | ;; (("xy" 1) . "x") | ||
| 132 | ;; (("xy" 2 1) . "y") | ||
| 133 | ;; (("xy" 0) . "") | ||
| 134 | ;; (("xy" 3) . "xy") | ||
| 135 | ;; (("中" 0) . "") | ||
| 136 | ;; (("中" 1) . "") | ||
| 137 | ;; (("中" 2) . "中") | ||
| 138 | ;; (("中" 1 nil ? ) . " ") | ||
| 139 | ;; (("中文" 3 1 ? ) . " ") | ||
| 140 | ;; (("x中x" 2) . "x") | ||
| 141 | ;; (("x中x" 3) . "x中") | ||
| 142 | ;; (("x中x" 3) . "x中") | ||
| 143 | ;; (("x中x" 4 1) . "中x") | ||
| 144 | ;; (("kor한e글an" 8 1 ? ) . "or한e글") | ||
| 145 | ;; (("kor한e글an" 7 2 ? ) . "r한e ") | ||
| 146 | ;; (("" 0 nil nil "...") . "") | ||
| 147 | ;; (("x" 3 nil nil "...") . "x") | ||
| 148 | ;; (("中" 3 nil nil "...") . "中") | ||
| 149 | ;; (("foo" 3 nil nil "...") . "foo") | ||
| 150 | ;; (("foo" 2 nil nil "...") . "fo") ;; XEmacs failure? | ||
| 151 | ;; (("foobar" 6 0 nil "...") . "foobar") | ||
| 152 | ;; (("foobarbaz" 6 nil nil "...") . "foo...") | ||
| 153 | ;; (("foobarbaz" 7 2 nil "...") . "ob...") | ||
| 154 | ;; (("foobarbaz" 9 3 nil "...") . "barbaz") | ||
| 155 | ;; (("こhんeにlちlはo" 15 1 ? t) . " hんeにlちlはo") | ||
| 156 | ;; (("こhんeにlちlはo" 14 1 ? t) . " hんeにlち...") | ||
| 157 | ;; (("x" 3 nil nil "粵語") . "x") | ||
| 158 | ;; (("中" 2 nil nil "粵語") . "中") | ||
| 159 | ;; (("中" 1 nil ?x "粵語") . "x") ;; XEmacs error | ||
| 160 | ;; (("中文" 3 nil ? "粵語") . "中 ") ;; XEmacs error | ||
| 161 | ;; (("foobarbaz" 4 nil nil "粵語") . "粵語") | ||
| 162 | ;; (("foobarbaz" 5 nil nil "粵語") . "f粵語") | ||
| 163 | ;; (("foobarbaz" 6 nil nil "粵語") . "fo粵語") | ||
| 164 | ;; (("foobarbaz" 8 3 nil "粵語") . "b粵語") | ||
| 165 | ;; (("こhんeにlちlはo" 14 4 ?x "日本語") . "xeに日本語") | ||
| 166 | ;; (("こhんeにlちlはo" 13 4 ?x "日本語") . "xex日本語") | ||
| 167 | ;; )) | ||
| 168 | ;; (let (ret) | ||
| 169 | ;; (condition-case e | ||
| 170 | ;; (setq ret (apply #'truncate-string-to-width (car test))) | ||
| 171 | ;; (error (setq ret e))) | ||
| 172 | ;; (unless (equal ret (cdr test)) | ||
| 173 | ;; (error "%s: expected %s, got %s" | ||
| 174 | ;; (prin1-to-string (cons 'truncate-string-to-width (car test))) | ||
| 175 | ;; (prin1-to-string (cdr test)) | ||
| 176 | ;; (if (consp ret) | ||
| 177 | ;; (format "error: %s: %s" (car ret) | ||
| 178 | ;; (prin1-to-string (cdr ret))) | ||
| 179 | ;; (prin1-to-string ret)))))) | ||
| 180 | |||
| 181 | 128 | ||
| 182 | ;;; Nested alist handler. Nested alist is alist whose elements are | 129 | ;;; Nested alist handler. Nested alist is alist whose elements are |
| 183 | ;;; also nested alist. | 130 | ;;; also nested alist. |
diff --git a/test/ChangeLog b/test/ChangeLog index d744a5c788d..2e4d19e7a36 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-08-05 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * automated/mule-util.el: New file, with tests extracted from | ||
| 4 | lisp/international/mule-util.el. | ||
| 5 | |||
| 1 | 2013-08-04 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2013-08-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * automated/advice-tests.el (advice-tests-nadvice): Test removal | 8 | * automated/advice-tests.el (advice-tests-nadvice): Test removal |
diff --git a/test/automated/mule-util.el b/test/automated/mule-util.el new file mode 100644 index 00000000000..3e269faad75 --- /dev/null +++ b/test/automated/mule-util.el | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | ;;; mule-util --- tests for international/mule-util.el -*- coding: utf-8; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2002-2013 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 | ;;; Commentary: | ||
| 21 | |||
| 22 | ;;; Code: | ||
| 23 | |||
| 24 | (require 'ert) | ||
| 25 | (require 'mule-util) | ||
| 26 | |||
| 27 | (defconst mule-util-test-truncate-data | ||
| 28 | '((("" 0) . "") | ||
| 29 | (("x" 1) . "x") | ||
| 30 | (("xy" 1) . "x") | ||
| 31 | (("xy" 2 1) . "y") | ||
| 32 | (("xy" 0) . "") | ||
| 33 | (("xy" 3) . "xy") | ||
| 34 | (("中" 0) . "") | ||
| 35 | (("中" 1) . "") | ||
| 36 | (("中" 2) . "中") | ||
| 37 | (("中" 1 nil ? ) . " ") | ||
| 38 | (("中文" 3 1 ? ) . " ") | ||
| 39 | (("x中x" 2) . "x") | ||
| 40 | (("x中x" 3) . "x中") | ||
| 41 | (("x中x" 3) . "x中") | ||
| 42 | (("x中x" 4 1) . "中x") | ||
| 43 | (("kor한e글an" 8 1 ? ) . "or한e글") | ||
| 44 | (("kor한e글an" 7 2 ? ) . "r한e ") | ||
| 45 | (("" 0 nil nil "...") . "") | ||
| 46 | (("x" 3 nil nil "...") . "x") | ||
| 47 | (("中" 3 nil nil "...") . "中") | ||
| 48 | (("foo" 3 nil nil "...") . "foo") | ||
| 49 | (("foo" 2 nil nil "...") . "fo") ;; XEmacs failure? | ||
| 50 | (("foobar" 6 0 nil "...") . "foobar") | ||
| 51 | (("foobarbaz" 6 nil nil "...") . "foo...") | ||
| 52 | (("foobarbaz" 7 2 nil "...") . "ob...") | ||
| 53 | (("foobarbaz" 9 3 nil "...") . "barbaz") | ||
| 54 | (("こhんeにlちlはo" 15 1 ? t) . " hんeにlちlはo") | ||
| 55 | (("こhんeにlちlはo" 14 1 ? t) . " hんeにlち...") | ||
| 56 | (("x" 3 nil nil "粵語") . "x") | ||
| 57 | (("中" 2 nil nil "粵語") . "中") | ||
| 58 | (("中" 1 nil ?x "粵語") . "x") ;; XEmacs error | ||
| 59 | (("中文" 3 nil ? "粵語") . "中 ") ;; XEmacs error | ||
| 60 | (("foobarbaz" 4 nil nil "粵語") . "粵語") | ||
| 61 | (("foobarbaz" 5 nil nil "粵語") . "f粵語") | ||
| 62 | (("foobarbaz" 6 nil nil "粵語") . "fo粵語") | ||
| 63 | (("foobarbaz" 8 3 nil "粵語") . "b粵語") | ||
| 64 | (("こhんeにlちlはo" 14 4 ?x "日本語") . "xeに日本語") | ||
| 65 | (("こhんeにlちlはo" 13 4 ?x "日本語") . "xex日本語") | ||
| 66 | ) | ||
| 67 | "Test data for `truncate-string-to-width'.") | ||
| 68 | |||
| 69 | (defun mule-util-test-truncate-create (n) | ||
| 70 | "Create a test for element N of the `mule-util-test-truncate-data' constant." | ||
| 71 | (let ((testname (intern (format "mule-util-test-truncate-%.2d" n))) | ||
| 72 | (testdoc (format "Test element %d of `mule-util-test-truncate-data'." | ||
| 73 | n)) | ||
| 74 | (testdata (nth n mule-util-test-truncate-data))) | ||
| 75 | (eval | ||
| 76 | `(ert-deftest ,testname () | ||
| 77 | ,testdoc | ||
| 78 | (should (equal (apply 'truncate-string-to-width ',(car testdata)) | ||
| 79 | ,(cdr testdata))))))) | ||
| 80 | |||
| 81 | (dotimes (i (length mule-util-test-truncate-data)) | ||
| 82 | (mule-util-test-truncate-create i)) | ||
| 83 | |||
| 84 | ;;; mule-util.el ends here | ||