From 88ade9c53dbcd0e72df80663f505b18ee048fbdf Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 16 Aug 2024 16:35:55 +0200 Subject: [PATCH] ; * test/lisp/emacs-lisp/scope-tests.el: Update tests. --- test/lisp/emacs-lisp/scope-tests.el | 121 +++++++++++++++------------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/test/lisp/emacs-lisp/scope-tests.el b/test/lisp/emacs-lisp/scope-tests.el index 39b3a268b31..cc2623aadbe 100644 --- a/test/lisp/emacs-lisp/scope-tests.el +++ b/test/lisp/emacs-lisp/scope-tests.el @@ -22,8 +22,21 @@ (require 'scope) (require 'ert) +(defmacro scope-test (given expected) + `(should (equal ,expected (let (all) + (scope (lambda (_type beg len bin) + (push (list beg len bin) all)) + ,given) + (reverse all))))) + (ert-deftest scope-test-1 () - (should (equal '((13 3 13) + (scope-test " +(defun foo (bar baz) + (let* ((baz baz) + (baz baz)) + (when (and bar spam baz) + (ignore bar baz))) + (ignore baz))" '((13 3 13) (17 3 17) (32 3 32) (36 3 17) @@ -32,35 +45,14 @@ (76 3 13) (80 4 nil) (85 3 51) - (97 6 function) + (97 6 nil) (104 3 13) (108 3 51) - (118 6 function) - (125 3 17)) - (scope " -(defun foo (bar baz) - (let* ((baz baz) - (baz baz)) - (when (and bar spam baz) - (ignore bar baz))) - (ignore baz))")))) + (118 6 nil) + (125 3 17)))) (ert-deftest scope-test-2 () - (should (equal '((110 11 110) - (133 16 function) - (197 6 197) - (228 7 function) - (236 6 197) - (257 2 257) - (263 3 263) - (287 2 287) - (290 3 263) - (313 2 257) - (317 9 function) - (327 2 287) - (330 11 110) - (353 11 110)) - (scope " + (scope-test " (defun refactor-backends () \"Return alist of refactor operations and backends that support them.\" (let ((op-be-alist nil)) @@ -71,24 +63,23 @@ (`(,be . ,ops) (dolist (op ops) (push be (alist-get op op-be-alist))))))) - op-be-alist))")))) + op-be-alist))" '((110 11 110) + (133 16 nil) + (197 6 197) + (228 7 nil) + (236 6 197) + (257 2 257) + (263 3 263) + (290 3 263) + (287 2 287) + (313 2 257) + (317 9 nil) + (327 2 287) + (330 11 110) + (353 11 110)))) (ert-deftest scope-test-3 () - (should (equal '((45 3 45) - (55 4 55) - (136 4 136) - (142 11 function) - (172 4 172) - (178 11 function) - (212 4 136) - (218 4 172) - (258 3 45) - (272 4 136) - (287 4 172) - (312 4 136) - (318 4 172) - (334 4 55)) - (scope " + (scope-test " (defmacro erc--with-entrypoint-environment (env &rest body) \"Run BODY with bindings from ENV alist.\" (declare (indent 1)) @@ -97,25 +88,41 @@ `(let (,syms ,vals) (pcase-dolist (`(,k . ,v) ,env) (push k ,syms) (push v ,vals)) (cl-progv ,syms ,vals - ,@body))))")))) + ,@body))))" '((45 3 45) + (55 4 55) + (136 4 136) + (142 11 nil) + (172 4 172) + (178 11 nil) + (212 4 136) + (218 4 172) + (258 3 45) + (272 4 136) + (287 4 172) + (312 4 136) + (318 4 172) + (334 4 55)))) (ert-deftest scope-test-4 () - (should (equal '((8 3 8) - (29 3 29) - (34 3 34) - (40 1 function) - (42 3 34) - (46 3 8) - (67 3 67) - (85 3 29) - (89 3 8) - (110 3 67) - (115 3 29) - (119 3 8)) - (scope " + (scope-test " (let ((foo 1)) (cl-flet ((foo (bar) (* bar foo))) (cl-block foo - (while (foo foo) (cl-return-from foo (foo foo))))))")))) + (while (foo foo) (cl-return-from foo (foo foo))))))" + '((8 3 8) + (29 3 29) + (34 3 34) + (40 1 nil) + (42 3 34) + (46 3 8) + (67 3 67) + (85 3 29) + (89 3 8) + (110 3 67) + (115 3 29) + (119 3 8)))) + +(ert-deftest scope-test-5 () + (scope-test "(cl-loop if 1 return (+ it it))" '((22 1 nil) (24 2 9) (27 2 9)))) ;;; scope-tests.el ends here -- 2.39.2