diff options
author | Ulrich Müller <ulm@gentoo.org> | 2024-10-08 22:38:54 +0200 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2024-10-08 22:38:54 +0200 |
commit | 9e719318d1841d36e35f76e58775ef2a44a81c37 (patch) | |
tree | 4fdf2dc277fd081f7c9209ed44be5a549269021a | |
parent | Update documentation (diff) | |
download | ebuild-mode-9e719318d1841d36e35f76e58775ef2a44a81c37.tar.gz ebuild-mode-9e719318d1841d36e35f76e58775ef2a44a81c37.tar.bz2 ebuild-mode-9e719318d1841d36e35f76e58775ef2a44a81c37.zip |
New test for font-lock keywords
* ebuild-mode.el (ebuild-mode-collect-and-split): Preserve order.
(ebuild-mode-font-lock-keywords): Add docstring.
* test/ebuild-mode-tests.el (ebuild-mode-test-collect-and-split):
Update.
(ebuild-mode-test-font-lock-keywords): New test.
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ebuild-mode.el | 47 | ||||
-rw-r--r-- | test/ebuild-mode-tests.el | 47 |
3 files changed, 66 insertions, 36 deletions
@@ -1,3 +1,11 @@ +2024-10-08 Ulrich Müller <ulm@gentoo.org> + + * ebuild-mode.el (ebuild-mode-collect-and-split): Preserve order. + (ebuild-mode-font-lock-keywords): Add docstring. + * test/ebuild-mode-tests.el (ebuild-mode-test-collect-and-split): + Update. + (ebuild-mode-test-font-lock-keywords): New test. + 2024-10-05 Ulrich Müller <ulm@gentoo.org> * ebuild-mode.texi (ebuild-repo-mode): Document the bug-reference diff --git a/ebuild-mode.el b/ebuild-mode.el index 768207a..d0a25e0 100644 --- a/ebuild-mode.el +++ b/ebuild-mode.el @@ -297,25 +297,27 @@ Compatibility function for XEmacs." "For alist SRC, collect elements with equal cdr and concat their cars. Optional argument LIMIT specifies the maximum length for the car of the elements." - (let (dst e) - (dolist (c src dst) - (setq e (rassoc (cdr c) dst)) - (cond - ((and e (or (not limit) - (<= (+ (length (car e)) (length (car c))) limit))) - ;; cdrs of new element C and previous element E are equal, - ;; and their combined length is below LIMIT => append to E - (setcar e (append (car e) (car c)))) - ((or (not limit) - (<= (length (car c)) limit)) - ;; new element C is small enough => push to DST - (push (cons (car c) (cdr c)) dst)) - (t - ;; otherwise, split the new element into chunks of length LIMIT - (let ((cc (car c))) - (while cc - (push (cons (last cc limit) (cdr c)) dst) - (setq cc (butlast cc limit))))))))) + (let (dst) + (dolist (c src) + (let ((e (rassoc (cdr c) dst))) + (cond + ((and e (or (not limit) + (<= (+ (length (car e)) (length (car c))) limit))) + ;; cdrs of new element C and previous element E are equal, + ;; and their combined length is below LIMIT => append to E + (setcar e (append (car e) (car c)))) + ((or (not limit) + (<= (length (car c)) limit)) + ;; new element C is small enough => push to DST + (push (cons (car c) (cdr c)) dst)) + (t + ;; otherwise, split the new element into pieces of length LIMIT + (let ((p (copy-sequence (car c)))) + (while p + (push (cons p (cdr c)) dst) + (and (setq p (nthcdr (1- limit) p)) + (setq p (prog1 (cdr p) (setcdr p nil)))))))))) + (nreverse dst))) ) (eval-when-compile @@ -329,8 +331,8 @@ of the elements." (regexp-opt (car x) t) (or (nth 3 x) "\\>")) (cadr x))) - ;; Emacs has a limit of 32 kbyte for the size of regular - ;; expressions. Unfortunately, this is a hard limit in Emacs' + ;; GNU Emacs has a limit of 32 KiB for the size of regular + ;; expressions. Unfortunately, this is a hard limit in the ;; C code, MAX_BUF_SIZE in regex.c, which cannot be increased. ;; Therefore, split the list into several parts with at most ;; 1000 keywords; this appears to keep the regexp size below @@ -345,7 +347,8 @@ of the elements." ebuild-mode-keywords-eclassdoc ebuild-mode-keywords-eclassdoc-warn ebuild-mode-keywords-eclass) - 1000)))) + 1000))) + "Expressions to highlight in `ebuild-mode'.") ;;; Mode definitions. diff --git a/test/ebuild-mode-tests.el b/test/ebuild-mode-tests.el index ac5674d..e3e39a7 100644 --- a/test/ebuild-mode-tests.el +++ b/test/ebuild-mode-tests.el @@ -66,6 +66,39 @@ (ebuild-mode-time-string "%Y-%m-%d %H:%M:%S") "2024-08-10 00:00:00")))) +(ert-deftest ebuild-mode-test-collect-and-split () + (let* ((alist '(((a b) z) ((c d) z) ((e) z) ((f) z) ((g h) z) + ((i j) y x) ((k) y x) ((l)) ((m) z) ((n o) y x) ((p)) + ((q r s t u v) w))) + (alist-copy (copy-tree alist))) + (should (equal (ebuild-mode-collect-and-split alist) + '(((a b c d e f g h m) z) ((i j k n o) y x) ((l p)) + ((q r s t u v) w)))) + (should (equal (ebuild-mode-collect-and-split alist 4) + '(((a b c d) z) ((e f g h) z) ((i j k) y x) ((l p)) + ((m) z) ((n o) y x) ((q r s t) w) ((u v) w)))) + ;; was it non-destructive? + (should (equal alist alist-copy)))) + +(ert-deftest ebuild-mode-test-font-lock-keywords () + (let ((case-fold-search nil) + (find-kw (lambda (key) + (catch 'found + (dolist (e ebuild-mode-font-lock-keywords) + (if (string-match (car e) key) + (throw 'found (cdr e)))))))) + ;; Verify that all regexps are below the 32 KiB limit. + ;; Our regexps are ASCII only, so don't bother with string-bytes + ;; (GNU Emacs), string-char-byte-conversion-info (XEmacs 21.5), + ;; or other horrid incompatibilities. + (should (< (apply #'max (mapcar (lambda (e) (length (car e))) + ebuild-mode-font-lock-keywords)) + 32768)) + (should (equal (funcall find-kw "doins") 'font-lock-builtin-face)) + (should (equal (funcall find-kw "elisp-compile") 'font-lock-type-face)) + (should (equal (funcall find-kw "# @ECLASS") '(1 font-lock-type-face t))) + (should-not (funcall find-kw "@ECLASS")))) + (ert-deftest ebuild-mode-test-font-lock () (with-temp-buffer (ebuild-mode-test-run-silently @@ -86,20 +119,6 @@ (search-forward "install") (should-not (get-text-property (match-beginning 0) 'face)))) -(ert-deftest ebuild-mode-test-collect-and-split () - (let* ((alist '(((a b) z) ((c d) z) ((e) z) ((f) z) ((g h) z) - ((i j) y x) ((k) y x) ((l)) ((m) z) ((n o) y x) ((p)) - ((q r s t u v) w))) - (alist-copy (copy-tree alist))) - (should (equal (ebuild-mode-collect-and-split alist) - '(((q r s t u v) w) ((l p)) ((i j k n o) y x) - ((a b c d e f g h m) z)))) - (should (equal (ebuild-mode-collect-and-split alist 4) - '(((q r) w) ((s t u v) w) ((n o) y x) ((m) z) ((l p)) - ((i j k) y x) ((e f g h) z) ((a b c d) z)))) - ;; was it non-destructive? - (should (equal alist alist-copy)))) - (ert-deftest ebuild-mode-test-update-copyright () (let ((ebuild-mode-update-copyright t)) (ebuild-mode-test-run-with-fixed-time |