aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2024-06-04 10:58:29 -0400
committerStefan Monnier2024-06-09 00:19:03 -0400
commit3ecc6b4f3c2b070ed2c4463e2c5d8755ccc19f1c (patch)
tree36ec13f004e81faad33f8a42e30a96c4a40451d5 /test
parentce5d004b5b093842d9c46976c50453015fe1a7e7 (diff)
downloademacs-3ecc6b4f3c2b070ed2c4463e2c5d8755ccc19f1c.tar.gz
emacs-3ecc6b4f3c2b070ed2c4463e2c5d8755ccc19f1c.zip
(find-auto-coding): Provide filename to `auto-coding-functions`
Allow `auto-coding-functions` to know the file name. Motivated by the needs of Editorconfig support. * lisp/international/mule.el (auto-coding-file-name): New var. (find-auto-coding): Let-bind it for `auto-coding-functions`. Document the expectation that the arg be an absolute file name. * doc/lispref/nonascii.texi (Default Coding Systems): Mention `auto-coding-file-name`. * test/lisp/international/mule-util-resources/test.utf-16le: New file. * test/lisp/international/mule-tests.el (mule-tests--dir): New var. (mule-tests--auto-coding): New fun. (mule-tests--auto-coding-functions): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/international/mule-tests.el19
-rw-r--r--test/lisp/international/mule-util-resources/test.utf-16lebin0 -> 26 bytes
2 files changed, 19 insertions, 0 deletions
diff --git a/test/lisp/international/mule-tests.el b/test/lisp/international/mule-tests.el
index 9a80ced55ae..9c869cc8e6f 100644
--- a/test/lisp/international/mule-tests.el
+++ b/test/lisp/international/mule-tests.el
@@ -25,6 +25,8 @@
25 25
26(require 'ert-x) ;For `ert-simulate-keys'. 26(require 'ert-x) ;For `ert-simulate-keys'.
27 27
28(defconst mule-tests--dir (file-name-directory (macroexp-file-name)))
29
28(ert-deftest find-auto-coding--bug27391 () 30(ert-deftest find-auto-coding--bug27391 ()
29 "Check that Bug#27391 is fixed." 31 "Check that Bug#27391 is fixed."
30 (with-temp-buffer 32 (with-temp-buffer
@@ -94,6 +96,23 @@
94 ;; The chinese-hz encoding is not ASCII compatible. 96 ;; The chinese-hz encoding is not ASCII compatible.
95 (should-not (coding-system-get 'chinese-hz :ascii-compatible-p))) 97 (should-not (coding-system-get 'chinese-hz :ascii-compatible-p)))
96 98
99(defun mule-tests--auto-coding (_size)
100 (when (and (stringp auto-coding-file-name)
101 (string-match-p "\\.utf-16le\\'" auto-coding-file-name))
102 'utf-16le-with-signature))
103
104(ert-deftest mule-tests--auto-coding-functions ()
105 (unwind-protect
106 (progn
107 (add-hook 'auto-coding-functions #'mule-tests--auto-coding)
108 (with-temp-buffer
109 (insert-file-contents
110 (expand-file-name "mule-util-resources/test.utf-16le"
111 mule-tests--dir))
112 (goto-char (point-min))
113 (should (search-forward "été" nil t))))
114 (remove-hook 'auto-coding-functions #'mule-tests--auto-coding)))
115
97;;; Testing `sgml-html-meta-auto-coding-function'. 116;;; Testing `sgml-html-meta-auto-coding-function'.
98 117
99(defvar sgml-html-meta-pre "<!doctype html><html><head>" 118(defvar sgml-html-meta-pre "<!doctype html><html><head>"
diff --git a/test/lisp/international/mule-util-resources/test.utf-16le b/test/lisp/international/mule-util-resources/test.utf-16le
new file mode 100644
index 00000000000..8536adb5341
--- /dev/null
+++ b/test/lisp/international/mule-util-resources/test.utf-16le
Binary files differ