Skip to content

Instantly share code, notes, and snippets.

@bryanwb
Last active Sep 20, 2016
Embed
What would you like to do?
;; use-region-p returns nil even though it is mocked using cl-flet
;; why?
(defun bwb-gitlab--get-line-nums ()
"Return line number(s) if applicable.
If region selected, returns range in url form"
(if (null (use-region-p))
(message "use-region-p is nil"))
(cond ((not (gitlab--viewing-filep)) "")
((use-region-p)
(format "#L%d-%d"
(line-number-at-pos (region-beginning))
(line-number-at-pos (region-end))))
(t
(format "#L%d" (line-number-at-pos (point))))))
(ert-deftest test-gitlab-determine-linenum ()
:tags '(browse)
(cl-flet ((use-region-p () t))
(save-excursion
(let ((buffer (find-file-noselect gitlab-readme)))
(set-buffer buffer)
(forward-line)
(forward-line)
(set-mark-command (point))
(beginning-of-buffer)
(should (s-equals? (bwb-gitlab--get-line-nums) "#L1-2"))
))))
;; actual result of (bwb-gitlab--get-line-nums) => "#L1"
;; and message "use-region-p" is nil shown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment