diff options
Diffstat (limited to 'test/src/coding-tests.el')
| -rw-r--r-- | test/src/coding-tests.el | 97 |
1 files changed, 74 insertions, 23 deletions
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el index e0cefa94356..f65d575d0c2 100644 --- a/test/src/coding-tests.el +++ b/test/src/coding-tests.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; coding-tests.el --- tests for text encoding and decoding | 1 | ;;; coding-tests.el --- tests for text encoding and decoding -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2013-2017 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2013-2022 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Eli Zaretskii <eliz@gnu.org> | 5 | ;; Author: Eli Zaretskii <eliz@gnu.org> |
| 6 | ;; Author: Kenichi Handa <handa@gnu.org> | 6 | ;; Author: Kenichi Handa <handa@gnu.org> |
| @@ -56,21 +56,22 @@ | |||
| 56 | (set-buffer-multibyte nil) | 56 | (set-buffer-multibyte nil) |
| 57 | (insert (encode-coding-string "あ" 'euc-jp) "\xd" "\n") | 57 | (insert (encode-coding-string "あ" 'euc-jp) "\xd" "\n") |
| 58 | (decode-coding-region (point-min) (point-max) 'euc-jp-dos) | 58 | (decode-coding-region (point-min) (point-max) 'euc-jp-dos) |
| 59 | (should-not (string-match-p "\^M" (buffer-string))))) | 59 | (should-not (string-search "\^M" (buffer-string))))) |
| 60 | 60 | ||
| 61 | ;; Return the contents (specified by CONTENT-TYPE; ascii, latin, or | 61 | ;; Return the contents (specified by CONTENT-TYPE; ascii, latin, or |
| 62 | ;; binary) of a test file. | 62 | ;; binary) of a test file. |
| 63 | (defun coding-tests-file-contents (content-type) | 63 | (defun coding-tests-file-contents (content-type) |
| 64 | (let* ((ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n") | 64 | (with-suppressed-warnings ((obsolete string-as-unibyte)) |
| 65 | (latin (concat ascii "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ\n")) | 65 | (let* ((ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n") |
| 66 | (binary (string-to-multibyte | 66 | (latin (concat ascii "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ\n")) |
| 67 | (concat (string-as-unibyte latin) | 67 | (binary (string-to-multibyte |
| 68 | (unibyte-string #xC0 #xC1 ?\n))))) | 68 | (concat (string-as-unibyte latin) |
| 69 | (cond ((eq content-type 'ascii) ascii) | 69 | (unibyte-string #xC0 #xC1 ?\n))))) |
| 70 | ((eq content-type 'latin) latin) | 70 | (cond ((eq content-type 'ascii) ascii) |
| 71 | ((eq content-type 'binary) binary) | 71 | ((eq content-type 'latin) latin) |
| 72 | (t | 72 | ((eq content-type 'binary) binary) |
| 73 | (error "Invalid file content type: %s" content-type))))) | 73 | (t |
| 74 | (error "Invalid file content type: %s" content-type)))))) | ||
| 74 | 75 | ||
| 75 | ;; Generate FILE with CONTENTS encoded by CODING-SYSTEM. | 76 | ;; Generate FILE with CONTENTS encoded by CODING-SYSTEM. |
| 76 | ;; whose encoding specified by CODING-SYSTEM. | 77 | ;; whose encoding specified by CODING-SYSTEM. |
| @@ -143,7 +144,7 @@ | |||
| 143 | ;; Optional 5th arg TRANSLATOR is a function to translate the original | 144 | ;; Optional 5th arg TRANSLATOR is a function to translate the original |
| 144 | ;; file contents to match with the expected result of decoding. For | 145 | ;; file contents to match with the expected result of decoding. For |
| 145 | ;; instance, when a file of dos eol-type is read by unix eol-type, | 146 | ;; instance, when a file of dos eol-type is read by unix eol-type, |
| 146 | ;; `decode-test-lf-to-crlf' must be specified. | 147 | ;; `coding-tests-lf-to-crlf' must be specified. |
| 147 | 148 | ||
| 148 | (defun coding-tests (content-type write-coding read-coding detected-coding | 149 | (defun coding-tests (content-type write-coding read-coding detected-coding |
| 149 | &optional translator) | 150 | &optional translator) |
| @@ -296,7 +297,7 @@ | |||
| 296 | ;;; decoder, not for regression testing. | 297 | ;;; decoder, not for regression testing. |
| 297 | 298 | ||
| 298 | (defun generate-ascii-file () | 299 | (defun generate-ascii-file () |
| 299 | (dotimes (i 100000) | 300 | (dotimes (_i 100000) |
| 300 | (insert-char ?a 80) | 301 | (insert-char ?a 80) |
| 301 | (insert "\n"))) | 302 | (insert "\n"))) |
| 302 | 303 | ||
| @@ -309,13 +310,13 @@ | |||
| 309 | (insert "\n"))) | 310 | (insert "\n"))) |
| 310 | 311 | ||
| 311 | (defun generate-mostly-nonascii-file () | 312 | (defun generate-mostly-nonascii-file () |
| 312 | (dotimes (i 30000) | 313 | (dotimes (_i 30000) |
| 313 | (insert-char ?a 80) | 314 | (insert-char ?a 80) |
| 314 | (insert "\n")) | 315 | (insert "\n")) |
| 315 | (dotimes (i 20000) | 316 | (dotimes (_i 20000) |
| 316 | (insert-char ?À 80) | 317 | (insert-char ?À 80) |
| 317 | (insert "\n")) | 318 | (insert "\n")) |
| 318 | (dotimes (i 10000) | 319 | (dotimes (_i 10000) |
| 319 | (insert-char ?あ 80) | 320 | (insert-char ?あ 80) |
| 320 | (insert "\n"))) | 321 | (insert "\n"))) |
| 321 | 322 | ||
| @@ -359,7 +360,7 @@ | |||
| 359 | (delete-region (point-min) (point)))))) | 360 | (delete-region (point-min) (point)))))) |
| 360 | 361 | ||
| 361 | (defun benchmark-decoder () | 362 | (defun benchmark-decoder () |
| 362 | (let ((gc-cons-threshold 4000000)) | 363 | (let ((gc-cons-threshold (max gc-cons-threshold 4000000))) |
| 363 | (insert "Without optimization:\n") | 364 | (insert "Without optimization:\n") |
| 364 | (dolist (files test-file-list) | 365 | (dolist (files test-file-list) |
| 365 | (dolist (file (cdr files)) | 366 | (dolist (file (cdr files)) |
| @@ -375,9 +376,59 @@ | |||
| 375 | (with-temp-buffer (insert-file-contents (car file)))))) | 376 | (with-temp-buffer (insert-file-contents (car file)))))) |
| 376 | (insert (format "%s: %s\n" (car file) result))))))) | 377 | (insert (format "%s: %s\n" (car file) result))))))) |
| 377 | 378 | ||
| 378 | ;; Local Variables: | 379 | (ert-deftest coding-nocopy-trivial () |
| 379 | ;; byte-compile-warnings: (not obsolete) | 380 | "Check that the NOCOPY parameter works for the trivial coding system." |
| 380 | ;; End: | 381 | (let ((s "abc")) |
| 382 | (should-not (eq (decode-coding-string s nil nil) s)) | ||
| 383 | (should (eq (decode-coding-string s nil t) s)) | ||
| 384 | (should-not (eq (encode-coding-string s nil nil) s)) | ||
| 385 | (should (eq (encode-coding-string s nil t) s)))) | ||
| 386 | |||
| 387 | (ert-deftest coding-nocopy-ascii () | ||
| 388 | "Check that the NOCOPY parameter works for ASCII-only strings." | ||
| 389 | (let* ((uni (apply #'string (number-sequence 0 127))) | ||
| 390 | (multi (string-to-multibyte uni))) | ||
| 391 | (dolist (s (list uni multi)) | ||
| 392 | ;; Encodings without EOL conversion. | ||
| 393 | (dolist (coding '(us-ascii-unix iso-latin-1-unix utf-8-unix)) | ||
| 394 | (should-not (eq (decode-coding-string s coding nil) s)) | ||
| 395 | (should-not (eq (encode-coding-string s coding nil) s)) | ||
| 396 | (should (eq (decode-coding-string s coding t) s)) | ||
| 397 | (should (eq (encode-coding-string s coding t) s)) | ||
| 398 | (should (eq last-coding-system-used coding))) | ||
| 399 | |||
| 400 | ;; With EOL conversion inhibited. | ||
| 401 | (let ((inhibit-eol-conversion t)) | ||
| 402 | (dolist (coding '(us-ascii iso-latin-1 utf-8)) | ||
| 403 | (should-not (eq (decode-coding-string s coding nil) s)) | ||
| 404 | (should-not (eq (encode-coding-string s coding nil) s)) | ||
| 405 | (should (eq (decode-coding-string s coding t) s)) | ||
| 406 | (should (eq (encode-coding-string s coding t) s)))))) | ||
| 407 | |||
| 408 | ;; Check identity decoding with EOL conversion for ASCII except CR. | ||
| 409 | (let* ((uni (apply #'string (delq ?\r (number-sequence 0 127)))) | ||
| 410 | (multi (string-to-multibyte uni))) | ||
| 411 | (dolist (s (list uni multi)) | ||
| 412 | (dolist (coding '(us-ascii-dos iso-latin-1-dos utf-8-dos mac-roman-mac)) | ||
| 413 | (should-not (eq (decode-coding-string s coding nil) s)) | ||
| 414 | (should (eq (decode-coding-string s coding t) s))))) | ||
| 415 | |||
| 416 | ;; Check identity encoding with EOL conversion for ASCII except LF. | ||
| 417 | (let* ((uni (apply #'string (delq ?\n (number-sequence 0 127)))) | ||
| 418 | (multi (string-to-multibyte uni))) | ||
| 419 | (dolist (s (list uni multi)) | ||
| 420 | (dolist (coding '(us-ascii-dos iso-latin-1-dos utf-8-dos mac-roman-mac)) | ||
| 421 | (should-not (eq (encode-coding-string s coding nil) s)) | ||
| 422 | (should (eq (encode-coding-string s coding t) s)))))) | ||
| 423 | |||
| 424 | |||
| 425 | (ert-deftest coding-check-coding-systems-region () | ||
| 426 | (should (equal (check-coding-systems-region "aå" nil '(utf-8)) | ||
| 427 | nil)) | ||
| 428 | (should (equal (check-coding-systems-region "aåbγc" nil | ||
| 429 | '(utf-8 iso-latin-1 us-ascii)) | ||
| 430 | '((iso-latin-1 3) (us-ascii 1 3)))) | ||
| 431 | (should-error (check-coding-systems-region "å" nil '(bad-coding-system)))) | ||
| 381 | 432 | ||
| 382 | (provide 'coding-tests) | 433 | (provide 'coding-tests) |
| 383 | ;; coding-tests.el ends here | 434 | ;;; coding-tests.el ends here |