diff options
| author | Paul Eggert | 2016-04-25 10:41:29 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-04-25 10:42:48 -0700 |
| commit | 86d083438dba60dc00e9e96414bf7e832720c05a (patch) | |
| tree | 9ca5fac163acf4b1a3bca0e1e8b5c87af26e5a89 /test/src | |
| parent | f069d854508946bcc03e4c77ceb430748e3ab6d7 (diff) | |
| download | emacs-86d083438dba60dc00e9e96414bf7e832720c05a.tar.gz emacs-86d083438dba60dc00e9e96414bf7e832720c05a.zip | |
New function ‘char-from-name’
This also fixes the mishandling of "\N{CJK COMPATIBILITY
IDEOGRAPH-F900}", "\N{VARIATION SELECTOR-1}", etc.
Problem reported by Eli Zaretskii in:
http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00614.html
* doc/lispref/nonascii.texi (Character Codes), etc/NEWS: Document this.
* lisp/international/mule-cmds.el (char-from-name): New function.
(read-char-by-name): Use it. Document that "BED" is treated as
a name, not as a hexadecimal number. Reject out-of-range integers,
floating-point numbers, and strings with trailing junk.
* src/lread.c (character_name_to_code): Call char-from-name
instead of inspecting ucs-names directly, so that we handle
computed names like "VARIATION SELECTOR-1". Do not use an auto
string, since char-from-name might GC.
* test/src/lread-tests.el: Add tests for new behavior, and
fix some old tests that were wrong.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/lread-tests.el | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 2ebaf491120..1a82d133a44 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -28,15 +28,55 @@ | |||
| 28 | (ert-deftest lread-char-number () | 28 | (ert-deftest lread-char-number () |
| 29 | (should (equal (read "?\\N{U+A817}") #xA817))) | 29 | (should (equal (read "?\\N{U+A817}") #xA817))) |
| 30 | 30 | ||
| 31 | (ert-deftest lread-char-name () | 31 | (ert-deftest lread-char-name-1 () |
| 32 | (should (equal (read "?\\N{SYLOTI NAGRI LETTER \n DHO}") | 32 | (should (equal (read "?\\N{SYLOTI NAGRI LETTER \n DHO}") |
| 33 | #xA817))) | 33 | #xA817))) |
| 34 | (ert-deftest lread-char-name-2 () | ||
| 35 | (should (equal (read "?\\N{BED}") #x1F6CF))) | ||
| 36 | (ert-deftest lread-char-name-3 () | ||
| 37 | (should (equal (read "?\\N{U+BED}") #xBED))) | ||
| 38 | (ert-deftest lread-char-name-4 () | ||
| 39 | (should (equal (read "?\\N{VARIATION SELECTOR-1}") #xFE00))) | ||
| 40 | (ert-deftest lread-char-name-5 () | ||
| 41 | (should (equal (read "?\\N{VARIATION SELECTOR-16}") #xFE0F))) | ||
| 42 | (ert-deftest lread-char-name-6 () | ||
| 43 | (should (equal (read "?\\N{VARIATION SELECTOR-17}") #xE0100))) | ||
| 44 | (ert-deftest lread-char-name-7 () | ||
| 45 | (should (equal (read "?\\N{VARIATION SELECTOR-256}") #xE01EF))) | ||
| 46 | (ert-deftest lread-char-name-8 () | ||
| 47 | (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-F900}") #xF900))) | ||
| 48 | (ert-deftest lread-char-name-9 () | ||
| 49 | (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-FAD9}") #xFAD9))) | ||
| 50 | (ert-deftest lread-char-name-10 () | ||
| 51 | (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2F800}") #x2F800))) | ||
| 52 | (ert-deftest lread-char-name-11 () | ||
| 53 | (should (equal (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2FA1D}") #x2FA1D))) | ||
| 34 | 54 | ||
| 35 | (ert-deftest lread-char-invalid-number () | 55 | (ert-deftest lread-char-invalid-number () |
| 36 | (should-error (read "?\\N{U+110000}") :type 'invalid-read-syntax)) | 56 | (should-error (read "?\\N{U+110000}") :type 'invalid-read-syntax)) |
| 37 | 57 | ||
| 38 | (ert-deftest lread-char-invalid-name () | 58 | (ert-deftest lread-char-invalid-name-1 () |
| 39 | (should-error (read "?\\N{DOES NOT EXIST}")) :type 'invalid-read-syntax) | 59 | (should-error (read "?\\N{DOES NOT EXIST}")) :type 'invalid-read-syntax) |
| 60 | (ert-deftest lread-char-invalid-name-2 () | ||
| 61 | (should-error (read "?\\N{VARIATION SELECTOR-0}")) :type 'invalid-read-syntax) | ||
| 62 | (ert-deftest lread-char-invalid-name-3 () | ||
| 63 | (should-error (read "?\\N{VARIATION SELECTOR-257}")) | ||
| 64 | :type 'invalid-read-syntax) | ||
| 65 | (ert-deftest lread-char-invalid-name-4 () | ||
| 66 | (should-error (read "?\\N{VARIATION SELECTOR--0}")) | ||
| 67 | :type 'invalid-read-syntax) | ||
| 68 | (ert-deftest lread-char-invalid-name-5 () | ||
| 69 | (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-F8FF}")) | ||
| 70 | :type 'invalid-read-syntax) | ||
| 71 | (ert-deftest lread-char-invalid-name-6 () | ||
| 72 | (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-FADA}")) | ||
| 73 | :type 'invalid-read-syntax) | ||
| 74 | (ert-deftest lread-char-invalid-name-7 () | ||
| 75 | (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2F7FF}")) | ||
| 76 | :type 'invalid-read-syntax) | ||
| 77 | (ert-deftest lread-char-invalid-name-8 () | ||
| 78 | (should-error (read "?\\N{CJK COMPATIBILITY IDEOGRAPH-2FA1E}")) | ||
| 79 | :type 'invalid-read-syntax) | ||
| 40 | 80 | ||
| 41 | (ert-deftest lread-char-non-ascii-name () | 81 | (ert-deftest lread-char-non-ascii-name () |
| 42 | (should-error (read "?\\N{LATIN CAPITAL LETTER Ø}") | 82 | (should-error (read "?\\N{LATIN CAPITAL LETTER Ø}") |
| @@ -55,13 +95,13 @@ | |||
| 55 | (should-error (read "?\\N{U+DFFF}") :type 'invalid-read-syntax)) | 95 | (should-error (read "?\\N{U+DFFF}") :type 'invalid-read-syntax)) |
| 56 | 96 | ||
| 57 | (ert-deftest lread-string-char-number-1 () | 97 | (ert-deftest lread-string-char-number-1 () |
| 58 | (should (equal (read "a\\N{U+A817}b") "a\uA817bx"))) | 98 | (should (equal (read "\"a\\N{U+A817}b\"") "a\uA817b"))) |
| 59 | (ert-deftest lread-string-char-number-2 () | 99 | (ert-deftest lread-string-char-number-2 () |
| 60 | (should-error (read "?\\N{0.5}") :type 'invalid-read-syntax)) | 100 | (should-error (read "?\\N{0.5}") :type 'invalid-read-syntax)) |
| 61 | (ert-deftest lread-string-char-number-3 () | 101 | (ert-deftest lread-string-char-number-3 () |
| 62 | (should-error (read "?\\N{U+-0}") :type 'invalid-read-syntax)) | 102 | (should-error (read "?\\N{U+-0}") :type 'invalid-read-syntax)) |
| 63 | 103 | ||
| 64 | (ert-deftest lread-string-char-name () | 104 | (ert-deftest lread-string-char-name () |
| 65 | (should (equal (read "a\\N{SYLOTI NAGRI LETTER DHO}b") "a\uA817b"))) | 105 | (should (equal (read "\"a\\N{SYLOTI NAGRI LETTER DHO}b\"") "a\uA817b"))) |
| 66 | 106 | ||
| 67 | ;;; lread-tests.el ends here | 107 | ;;; lread-tests.el ends here |