aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2013-06-28 23:39:40 +0900
committerKenichi Handa2013-06-28 23:39:40 +0900
commit3e3da660306d977c1fd7090c067c9324ab111c04 (patch)
tree006249ea754315410ed33ff78bb59153ebd8b537
parent2e667b8ccd507148aa40ad37546b042398234ab8 (diff)
downloademacs-3e3da660306d977c1fd7090c067c9324ab111c04.tar.gz
emacs-3e3da660306d977c1fd7090c067c9324ab111c04.zip
decoder-tests.el (decoder-tests-gen-file): New arg FILE.
(decoder-tests-ao-gen-file): Renamed from decoder-tests-filename. Callers changed. (decoder-tests-filename): New function. (decoder-tests-prefer-utf-8-read) (decoder-tests-prefer-utf-8-write): New function. (ert-test-decoder-prefer-utf-8): New test.
-rw-r--r--test/ChangeLog10
-rw-r--r--test/automated/decoder-tests.el117
2 files changed, 104 insertions, 23 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 73ce74a02ae..4bc099e02ad 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,13 @@
12013-06-28 Kenichi Handa <handa@gnu.org>
2
3 * automated/decoder-tests.el (decoder-tests-gen-file): New arg FILE.
4 (decoder-tests-ao-gen-file): Renamed from decoder-tests-filename.
5 Callers changed.
6 (decoder-tests-filename): New function.
7 (decoder-tests-prefer-utf-8-read)
8 (decoder-tests-prefer-utf-8-write): New function.
9 (ert-test-decoder-prefer-utf-8): New test.
10
12013-06-21 Eduard Wiebe <usenet@pusto.de> 112013-06-21 Eduard Wiebe <usenet@pusto.de>
2 12
3 Test suite for flymake. 13 Test suite for flymake.
diff --git a/test/automated/decoder-tests.el b/test/automated/decoder-tests.el
index 055626491c0..e1b05faf3c0 100644
--- a/test/automated/decoder-tests.el
+++ b/test/automated/decoder-tests.el
@@ -23,12 +23,14 @@
23 23
24(require 'ert) 24(require 'ert)
25 25
26;;; Check ASCII optimizing decoder
27
28;; Directory to hold test data files. 26;; Directory to hold test data files.
29(defvar decoder-tests-workdir 27(defvar decoder-tests-workdir
30 (expand-file-name "decoder-tests" temporary-file-directory)) 28 (expand-file-name "decoder-tests" temporary-file-directory))
31 29
30;; Remove all generated test files.
31(defun decoder-tests-remove-files ()
32 (delete-directory decoder-tests-workdir t))
33
32;; Return the contents (specified by CONTENT-TYPE; ascii, latin, or 34;; Return the contents (specified by CONTENT-TYPE; ascii, latin, or
33;; binary) of a test file. 35;; binary) of a test file.
34(defun decoder-tests-file-contents (content-type) 36(defun decoder-tests-file-contents (content-type)
@@ -43,25 +45,16 @@
43 (t 45 (t
44 (error "Invalid file content type: %s" content-type))))) 46 (error "Invalid file content type: %s" content-type)))))
45 47
46;; Return the name of test file whose contents specified by 48;; Generate FILE with CONTENTS encoded by CODING-SYSTEM.
47;; CONTENT-TYPE and whose encoding specified by CODING-SYSTEM.
48(defun decoder-tests-filename (content-type coding-system)
49 (expand-file-name (format "%s-%s" content-type coding-system)
50 decoder-tests-workdir))
51
52;; Generate a test file whose contents specified by CONTENT-TYPE and
53;; whose encoding specified by CODING-SYSTEM. 49;; whose encoding specified by CODING-SYSTEM.
54(defun decoder-tests-gen-file (content-type coding-system) 50(defun decoder-tests-gen-file (file contents coding-system)
55 (or (file-directory-p decoder-tests-workdir) 51 (or (file-directory-p decoder-tests-workdir)
56 (mkdir decoder-tests-workdir t)) 52 (mkdir decoder-tests-workdir t))
57 (let ((file (decoder-tests-filename content-type coding-system))) 53 (setq file (expand-file-name file decoder-tests-workdir))
58 (with-temp-file file 54 (with-temp-file file
59 (set-buffer-file-coding-system coding-system) 55 (set-buffer-file-coding-system coding-system)
60 (insert (decoder-tests-file-contents content-type))))) 56 (insert contents))
61 57 file)
62;; Remove all generated test files.
63(defun decoder-tests-remove-files ()
64 (delete-directory decoder-tests-workdir t))
65 58
66;;; The following three functions are filters for contents of a test 59;;; The following three functions are filters for contents of a test
67;;; file. 60;;; file.
@@ -96,6 +89,26 @@
96(defun decoder-tests-add-bom (str) 89(defun decoder-tests-add-bom (str)
97 (concat "\xfeff" str)) 90 (concat "\xfeff" str))
98 91
92;; Return the name of test file whose contents specified by
93;; CONTENT-TYPE and whose encoding specified by CODING-SYSTEM.
94(defun decoder-tests-filename (content-type coding-system &optional ext)
95 (if ext
96 (expand-file-name (format "%s-%s.%s" content-type coding-system ext)
97 decoder-tests-workdir)
98 (expand-file-name (format "%s-%s" content-type coding-system)
99 decoder-tests-workdir)))
100
101
102;;; Check ASCII optimizing decoder
103
104;; Generate a test file whose contents specified by CONTENT-TYPE and
105;; whose encoding specified by CODING-SYSTEM.
106(defun decoder-tests-ao-gen-file (content-type coding-system)
107 (let ((file (decoder-tests-filename content-type coding-system)))
108 (decoder-tests-gen-file file
109 (decoder-tests-file-contents content-type)
110 coding-system)))
111
99;; Test the decoding of a file whose contents and encoding are 112;; Test the decoding of a file whose contents and encoding are
100;; specified by CONTENT-TYPE and WRITE-CODING. The test passes if the 113;; specified by CONTENT-TYPE and WRITE-CODING. The test passes if the
101;; file is read by READ-CODING and detected as DETECTED-CODING and the 114;; file is read by READ-CODING and detected as DETECTED-CODING and the
@@ -127,7 +140,7 @@
127 (unwind-protect 140 (unwind-protect
128 (progn 141 (progn
129 (dolist (eol-type '(unix dos mac)) 142 (dolist (eol-type '(unix dos mac))
130 (decoder-tests-gen-file 'ascii eol-type)) 143 (decoder-tests-ao-gen-file 'ascii eol-type))
131 (should-not (decoder-tests 'ascii 'unix 'undecided 'unix)) 144 (should-not (decoder-tests 'ascii 'unix 'undecided 'unix))
132 (should-not (decoder-tests 'ascii 'dos 'undecided 'dos)) 145 (should-not (decoder-tests 'ascii 'dos 'undecided 'dos))
133 (should-not (decoder-tests 'ascii 'dos 'dos 'dos)) 146 (should-not (decoder-tests 'ascii 'dos 'dos 'dos))
@@ -147,8 +160,8 @@
147 (progn 160 (progn
148 (dolist (coding '("utf-8" "utf-8-with-signature")) 161 (dolist (coding '("utf-8" "utf-8-with-signature"))
149 (dolist (eol-type '("unix" "dos" "mac")) 162 (dolist (eol-type '("unix" "dos" "mac"))
150 (decoder-tests-gen-file 'latin 163 (decoder-tests-ao-gen-file 'latin
151 (intern (concat coding "-" eol-type))))) 164 (intern (concat coding "-" eol-type)))))
152 (should-not (decoder-tests 'latin 'utf-8-unix 'undecided 'utf-8-unix)) 165 (should-not (decoder-tests 'latin 'utf-8-unix 'undecided 'utf-8-unix))
153 (should-not (decoder-tests 'latin 'utf-8-unix 'utf-8-unix 'utf-8-unix)) 166 (should-not (decoder-tests 'latin 'utf-8-unix 'utf-8-unix 'utf-8-unix))
154 (should-not (decoder-tests 'latin 'utf-8-dos 'undecided 'utf-8-dos)) 167 (should-not (decoder-tests 'latin 'utf-8-dos 'undecided 'utf-8-dos))
@@ -177,8 +190,8 @@
177 (unwind-protect 190 (unwind-protect
178 (progn 191 (progn
179 (dolist (eol-type '("unix" "dos" "mac")) 192 (dolist (eol-type '("unix" "dos" "mac"))
180 (decoder-tests-gen-file 'binary 193 (decoder-tests-ao-gen-file 'binary
181 (intern (concat "raw-text" "-" eol-type)))) 194 (intern (concat "raw-text" "-" eol-type))))
182 (should-not (decoder-tests 'binary 'raw-text-unix 'undecided 195 (should-not (decoder-tests 'binary 'raw-text-unix 'undecided
183 'raw-text-unix)) 196 'raw-text-unix))
184 (should-not (decoder-tests 'binary 'raw-text-dos 'undecided 197 (should-not (decoder-tests 'binary 'raw-text-dos 'undecided
@@ -193,6 +206,64 @@
193 'raw-text-mac 'decoder-tests-lf-to-lflf))) 206 'raw-text-mac 'decoder-tests-lf-to-lflf)))
194 (decoder-tests-remove-files))) 207 (decoder-tests-remove-files)))
195 208
209
210;;; Check the coding system `prefer-utf-8'.
211
212;; Read FILE. Check if the encoding was detected as DETECT. If
213;; PREFER is non-nil, prefer that coding system before reading.
214
215(defun decoder-tests-prefer-utf-8-read (file detect prefer)
216 (if prefer
217 (prefer-coding-system prefer))
218 (with-temp-buffer
219 (insert-file-contents file)
220 (if (eq buffer-file-coding-system detect)
221 nil
222 (format "Invalid detection: %s" buffer-file-coding-system))))
223
224;; Read FILE, modify it, and write it. Check if the coding system
225;; used for writing was CODING. If CODING-TAG is non-nil, insert
226;; coding tag with it before writing. If STR is non-nil, insert it
227;; before writing.
228
229(defun decoder-tests-prefer-utf-8-write (file coding-tag coding
230 &optional str)
231 (with-temp-buffer
232 (insert-file-contents file)
233 (goto-char (point-min))
234 (if coding-tag
235 (insert (format ";; -*- coding: %s; -*-\n" coding-tag))
236 (insert ";;\n"))
237 (if str
238 (insert str))
239 (write-file (decoder-tests-filename 'test 'test "el"))
240 (if (coding-system-equal buffer-file-coding-system coding)
241 nil
242 (format "Incorrect encoding: %s" last-coding-system-used))))
243
244(ert-deftest ert-test-decoder-prefer-utf-8 ()
245 (unwind-protect
246 (let ((ascii (decoder-tests-gen-file "ascii.el"
247 (decoder-tests-file-contents 'ascii)
248 'unix))
249 (latin (decoder-tests-gen-file "utf-8.el"
250 (decoder-tests-file-contents 'latin)
251 'utf-8)))
252 (should-not (decoder-tests-prefer-utf-8-read
253 ascii 'prefer-utf-8-unix nil))
254 (should-not (decoder-tests-prefer-utf-8-read
255 latin 'utf-8-unix nil))
256 (should-not (decoder-tests-prefer-utf-8-read
257 latin 'utf-8-unix 'iso-8859-1))
258 (should-not (decoder-tests-prefer-utf-8-read
259 latin 'utf-8-unix 'sjis))
260 (should-not (decoder-tests-prefer-utf-8-write
261 ascii nil 'prefer-utf-8-unix))
262 (should-not (decoder-tests-prefer-utf-8-write
263 ascii 'iso-8859-1 'iso-8859-1-unix))
264 (should-not (decoder-tests-prefer-utf-8-write
265 ascii nil 'utf-8-unix "À")))
266 (decoder-tests-remove-files)))
196 267
197 268
198;;; The following is for benchmark testing of the new optimized 269;;; The following is for benchmark testing of the new optimized