diff options
| author | Mattias Engdegård | 2023-03-25 17:43:43 +0100 |
|---|---|---|
| committer | Mattias Engdegård | 2023-03-25 17:43:43 +0100 |
| commit | d02f0221c41bf8b248d79e3aaebdec68789001da (patch) | |
| tree | fee6d4b168b21e192efcbf0838309b2d5362570f | |
| parent | 52b67740d10df8ca539fdc2c7d50283997683141 (diff) | |
| download | emacs-d02f0221c41bf8b248d79e3aaebdec68789001da.tar.gz emacs-d02f0221c41bf8b248d79e3aaebdec68789001da.zip | |
Fix shortdoc-tests when Unicode arrows can be displayed
New shortdoc functions use Unicode arrows when possible, which caused
some tests to fail if run under such circumstances.
* test/lisp/emacs-lisp/shortdoc-tests.el
(shortdoc-tests--to-ascii): New function.
(shortdoc-function-examples-test)
(shortdoc-help-fns-examples-function-test): Call it.
| -rw-r--r-- | test/lisp/emacs-lisp/shortdoc-tests.el | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/test/lisp/emacs-lisp/shortdoc-tests.el b/test/lisp/emacs-lisp/shortdoc-tests.el index d2dfbc66864..596b47d2543 100644 --- a/test/lisp/emacs-lisp/shortdoc-tests.el +++ b/test/lisp/emacs-lisp/shortdoc-tests.el | |||
| @@ -65,30 +65,48 @@ | |||
| 65 | (when buf | 65 | (when buf |
| 66 | (kill-buffer buf)))))) | 66 | (kill-buffer buf)))))) |
| 67 | 67 | ||
| 68 | (defun shortdoc-tests--to-ascii (x) | ||
| 69 | "Translate Unicode arrows to ASCII for making the test work everywhere." | ||
| 70 | (cond ((consp x) | ||
| 71 | (cons (shortdoc-tests--to-ascii (car x)) | ||
| 72 | (shortdoc-tests--to-ascii (cdr x)))) | ||
| 73 | ((stringp x) | ||
| 74 | (thread-last x | ||
| 75 | (string-replace "⇒" "=>") | ||
| 76 | (string-replace "→" "->"))) | ||
| 77 | (t x))) | ||
| 78 | |||
| 68 | (ert-deftest shortdoc-function-examples-test () | 79 | (ert-deftest shortdoc-function-examples-test () |
| 69 | "Test the extraction of usage examples of some Elisp functions." | 80 | "Test the extraction of usage examples of some Elisp functions." |
| 70 | (should (equal '((list . "(delete 2 (list 1 2 3 4))\n => (1 3 4)\n (delete \"a\" (list \"a\" \"b\" \"c\" \"d\"))\n => (\"b\" \"c\" \"d\")")) | 81 | (should (equal '((list . "(delete 2 (list 1 2 3 4))\n => (1 3 4)\n (delete \"a\" (list \"a\" \"b\" \"c\" \"d\"))\n => (\"b\" \"c\" \"d\")")) |
| 71 | (shortdoc-function-examples 'delete))) | 82 | (shortdoc-tests--to-ascii |
| 83 | (shortdoc-function-examples 'delete)))) | ||
| 72 | (should (equal '((alist . "(assq 'foo '((foo . bar) (zot . baz)))\n => (foo . bar)") | 84 | (should (equal '((alist . "(assq 'foo '((foo . bar) (zot . baz)))\n => (foo . bar)") |
| 73 | (list . "(assq 'b '((a . 1) (b . 2)))\n => (b . 2)")) | 85 | (list . "(assq 'b '((a . 1) (b . 2)))\n => (b . 2)")) |
| 74 | (shortdoc-function-examples 'assq))) | 86 | (shortdoc-tests--to-ascii |
| 87 | (shortdoc-function-examples 'assq)))) | ||
| 75 | (should (equal '((regexp . "(string-match-p \"^[fo]+\" \"foobar\")\n => 0")) | 88 | (should (equal '((regexp . "(string-match-p \"^[fo]+\" \"foobar\")\n => 0")) |
| 76 | (shortdoc-function-examples 'string-match-p)))) | 89 | (shortdoc-tests--to-ascii |
| 90 | (shortdoc-function-examples 'string-match-p))))) | ||
| 77 | 91 | ||
| 78 | (ert-deftest shortdoc-help-fns-examples-function-test () | 92 | (ert-deftest shortdoc-help-fns-examples-function-test () |
| 79 | "Test that `shortdoc-help-fns-examples-function' correctly prints ELisp function examples." | 93 | "Test that `shortdoc-help-fns-examples-function' correctly prints ELisp function examples." |
| 80 | (with-temp-buffer | 94 | (with-temp-buffer |
| 81 | (shortdoc-help-fns-examples-function 'string-fill) | 95 | (shortdoc-help-fns-examples-function 'string-fill) |
| 82 | (should (equal "\n Examples:\n\n (string-fill \"Three short words\" 12)\n => \"Three short\\nwords\"\n (string-fill \"Long-word\" 3)\n => \"Long-word\"\n\n" | 96 | (should (equal "\n Examples:\n\n (string-fill \"Three short words\" 12)\n => \"Three short\\nwords\"\n (string-fill \"Long-word\" 3)\n => \"Long-word\"\n\n" |
| 83 | (buffer-substring-no-properties (point-min) (point-max)))) | 97 | (shortdoc-tests--to-ascii |
| 98 | (buffer-substring-no-properties (point-min) (point-max))))) | ||
| 84 | (erase-buffer) | 99 | (erase-buffer) |
| 85 | (shortdoc-help-fns-examples-function 'assq) | 100 | (shortdoc-help-fns-examples-function 'assq) |
| 86 | (should (equal "\n Examples:\n\n (assq 'foo '((foo . bar) (zot . baz)))\n => (foo . bar)\n\n (assq 'b '((a . 1) (b . 2)))\n => (b . 2)\n\n" | 101 | (should (equal "\n Examples:\n\n (assq 'foo '((foo . bar) (zot . baz)))\n => (foo . bar)\n\n (assq 'b '((a . 1) (b . 2)))\n => (b . 2)\n\n" |
| 87 | (buffer-substring-no-properties (point-min) (point-max)))) | 102 | (shortdoc-tests--to-ascii |
| 103 | (buffer-substring-no-properties (point-min) (point-max))))) | ||
| 88 | (erase-buffer) | 104 | (erase-buffer) |
| 89 | (shortdoc-help-fns-examples-function 'string-trim) | 105 | (shortdoc-help-fns-examples-function 'string-trim) |
| 90 | (should (equal "\n Example:\n\n (string-trim \" foo \")\n => \"foo\"\n\n" | 106 | (should (equal "\n Example:\n\n (string-trim \" foo \")\n => \"foo\"\n\n" |
| 91 | (buffer-substring-no-properties (point-min) (point-max)))))) | 107 | (shortdoc-tests--to-ascii |
| 108 | (buffer-substring-no-properties (point-min) | ||
| 109 | (point-max))))))) | ||
| 92 | 110 | ||
| 93 | (provide 'shortdoc-tests) | 111 | (provide 'shortdoc-tests) |
| 94 | 112 | ||