(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)
(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))
(`(,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))
`(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