Skip to content

Instantly share code, notes, and snippets.

Last active Sep 20, 2016
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)) "")
(format "#L%d-%d"
(line-number-at-pos (region-beginning))
(line-number-at-pos (region-end))))
(format "#L%d" (line-number-at-pos (point))))))
(ert-deftest test-gitlab-determine-linenum ()
:tags '(browse)
(cl-flet ((use-region-p () t))
(let ((buffer (find-file-noselect gitlab-readme)))
(set-buffer buffer)
(set-mark-command (point))
(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