diff options
| author | Eric S. Raymond | 2026-02-25 19:39:31 -0500 |
|---|---|---|
| committer | Eric S. Raymond | 2026-02-25 19:41:05 -0500 |
| commit | 5749b2e4f4d11dd646892e70f520700e4f0f16f5 (patch) | |
| tree | 6adeb82a9c90e7bf1aafceb30595e90af3ef7674 /test/src/coding-tests.el | |
| parent | b09f8df206aae1e4b70d8961e6693d574aea6a30 (diff) | |
| download | emacs-5749b2e4f4d11dd646892e70f520700e4f0f16f5.tar.gz emacs-5749b2e4f4d11dd646892e70f520700e4f0f16f5.zip | |
Tests for primitives in coding.c and charset.c.
Diffstat (limited to 'test/src/coding-tests.el')
| -rw-r--r-- | test/src/coding-tests.el | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el index 4529002ad3b..c318b6f4e50 100644 --- a/test/src/coding-tests.el +++ b/test/src/coding-tests.el | |||
| @@ -24,6 +24,10 @@ | |||
| 24 | 24 | ||
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | 26 | ||
| 27 | ;; Optional internal helpers (only defined with ENABLE_UTF_8_CONVERTER_TEST). | ||
| 28 | (declare-function internal-encode-string-utf-8 "coding.c") | ||
| 29 | (declare-function internal-decode-string-utf-8 "coding.c") | ||
| 30 | |||
| 27 | ;; Directory to hold test data files. | 31 | ;; Directory to hold test data files. |
| 28 | (defvar coding-tests-workdir | 32 | (defvar coding-tests-workdir |
| 29 | (expand-file-name "coding-tests" temporary-file-directory)) | 33 | (expand-file-name "coding-tests" temporary-file-directory)) |
| @@ -472,5 +476,108 @@ | |||
| 472 | '((iso-latin-1 3) (us-ascii 1 3)))) | 476 | '((iso-latin-1 3) (us-ascii 1 3)))) |
| 473 | (should-error (check-coding-systems-region "å" nil '(bad-coding-system)))) | 477 | (should-error (check-coding-systems-region "å" nil '(bad-coding-system)))) |
| 474 | 478 | ||
| 479 | (ert-deftest coding-tests--detect-coding-string-null-byte () | ||
| 480 | (let ((inhibit-null-byte-detection nil)) | ||
| 481 | (should (memq 'no-conversion | ||
| 482 | (detect-coding-string (string ?a ?\0 ?b))))) | ||
| 483 | (let ((inhibit-null-byte-detection t)) | ||
| 484 | (should (memq 'undecided | ||
| 485 | (detect-coding-string (string ?a ?\0 ?b)))))) | ||
| 486 | |||
| 487 | (ert-deftest coding-tests--detect-coding-string-iso-escape () | ||
| 488 | (let ((s (decode-coding-string | ||
| 489 | (unibyte-string #x1b ?$ ?B ?A ?A #x1b ?\( ?B) | ||
| 490 | 'no-conversion))) | ||
| 491 | (let ((inhibit-iso-escape-detection nil)) | ||
| 492 | (should (memq 'iso-2022-7bit (detect-coding-string s)))) | ||
| 493 | (let ((inhibit-iso-escape-detection t)) | ||
| 494 | (should (memq 'undecided (detect-coding-string s)))))) | ||
| 495 | |||
| 496 | (ert-deftest coding-tests--detect-coding-region () | ||
| 497 | (with-temp-buffer | ||
| 498 | (insert "abc") | ||
| 499 | (let ((coding (detect-coding-region (point-min) (point-max) t))) | ||
| 500 | (should (coding-system-p coding))))) | ||
| 501 | |||
| 502 | (ert-deftest coding-tests--find-coding-systems-region-internal () | ||
| 503 | (should (eq (find-coding-systems-region-internal "abc" nil nil) t)) | ||
| 504 | (let ((result (find-coding-systems-region-internal (string #x03B1) | ||
| 505 | nil nil))) | ||
| 506 | (should (listp result)) | ||
| 507 | (should (memq 'utf-8 result)))) | ||
| 508 | |||
| 509 | (ert-deftest coding-tests--decode-encode-sjis () | ||
| 510 | (should (equal (decode-sjis-char #x82A0) ?あ)) | ||
| 511 | (should (= (encode-sjis-char ?あ) #x82A0)) | ||
| 512 | (should-error (decode-sjis-char #x817F))) | ||
| 513 | |||
| 514 | (ert-deftest coding-tests--decode-encode-big5 () | ||
| 515 | (should (equal (decode-big5-char ?A) ?A)) | ||
| 516 | (should (= (encode-big5-char ?A) ?A)) | ||
| 517 | (should-error (decode-big5-char #xA17F))) | ||
| 518 | |||
| 519 | (ert-deftest coding-tests--terminal-coding-system-internal () | ||
| 520 | (let ((orig (terminal-coding-system))) | ||
| 521 | (unwind-protect | ||
| 522 | (progn | ||
| 523 | (set-terminal-coding-system-internal 'utf-8 nil) | ||
| 524 | (should (eq (terminal-coding-system) 'utf-8)) | ||
| 525 | (set-safe-terminal-coding-system-internal 'us-ascii)) | ||
| 526 | (set-terminal-coding-system-internal (or orig 'undecided) nil)))) | ||
| 527 | |||
| 528 | (ert-deftest coding-tests--keyboard-coding-system-internal () | ||
| 529 | (let ((orig (keyboard-coding-system))) | ||
| 530 | (unwind-protect | ||
| 531 | (progn | ||
| 532 | (set-keyboard-coding-system-internal 'utf-8 nil) | ||
| 533 | (should (eq (keyboard-coding-system) 'utf-8))) | ||
| 534 | (set-keyboard-coding-system-internal orig nil)))) | ||
| 535 | |||
| 536 | (ert-deftest coding-tests--find-operation-coding-system () | ||
| 537 | (let ((file-coding-system-alist '(("foo\\.txt\\'" . utf-8)))) | ||
| 538 | (should (equal (find-operation-coding-system 'insert-file-contents | ||
| 539 | "foo.txt") | ||
| 540 | '(utf-8 . utf-8)))) | ||
| 541 | (let ((file-coding-system-alist '(("foo\\.txt\\'" . coding-tests--cs-fn)))) | ||
| 542 | (defun coding-tests--cs-fn (_args) 'utf-8) | ||
| 543 | (should (equal (find-operation-coding-system 'insert-file-contents | ||
| 544 | "foo.txt") | ||
| 545 | '(utf-8 . utf-8))))) | ||
| 546 | |||
| 547 | (ert-deftest coding-tests--set-coding-system-priority () | ||
| 548 | (let ((orig (coding-system-priority-list))) | ||
| 549 | (unwind-protect | ||
| 550 | (progn | ||
| 551 | (set-coding-system-priority 'utf-8) | ||
| 552 | (should (eq (coding-system-priority-list t) 'utf-8))) | ||
| 553 | (apply #'set-coding-system-priority orig)))) | ||
| 554 | |||
| 555 | (defvar coding-tests--internal-counter 0) | ||
| 556 | |||
| 557 | (ert-deftest coding-tests--define-coding-system-internal () | ||
| 558 | (let* ((name (intern (format "coding-tests--raw-%d" | ||
| 559 | (setq coding-tests--internal-counter | ||
| 560 | (1+ coding-tests--internal-counter))))) | ||
| 561 | (plist (list :docstring "coding-tests raw"))) | ||
| 562 | (define-coding-system-internal name ?r 'raw-text (list 'ascii) | ||
| 563 | t nil nil nil nil ?\ t plist 'unix) | ||
| 564 | (should (coding-system-p name)) | ||
| 565 | (should (equal (plist-get (coding-system-plist name) :docstring) | ||
| 566 | "coding-tests raw")) | ||
| 567 | (let ((alias (intern (format "coding-tests--raw-alias-%d" | ||
| 568 | coding-tests--internal-counter)))) | ||
| 569 | (define-coding-system-alias alias name) | ||
| 570 | (should (memq alias (coding-system-aliases name))) | ||
| 571 | (should (eq (coding-system-base alias) name))))) | ||
| 572 | |||
| 573 | (ert-deftest coding-tests--internal-utf-8-converters () | ||
| 574 | (skip-unless (fboundp 'internal-encode-string-utf-8)) | ||
| 575 | (let ((enc (internal-encode-string-utf-8 "abc" nil nil nil nil nil 1)) | ||
| 576 | (dec (internal-decode-string-utf-8 "abc" nil nil nil nil nil 1))) | ||
| 577 | (should (stringp enc)) | ||
| 578 | (should (equal enc "abc")) | ||
| 579 | (should (stringp dec)) | ||
| 580 | (should (equal dec "abc")))) | ||
| 581 | |||
| 475 | (provide 'coding-tests) | 582 | (provide 'coding-tests) |
| 476 | ;;; coding-tests.el ends here | 583 | ;;; coding-tests.el ends here |