aboutsummaryrefslogtreecommitdiff
path: root/tests/test-jumper--location-candidates.el
blob: df095830af34cf753a7024e0fd6869c395343d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; test-jumper--location-candidates.el --- Tests for jumper--location-candidates -*- lexical-binding: t; -*-

;;; Commentary:
;; jumper--location-candidates is the (display . index) builder extracted from
;; the verbatim cl-loop in jumper-jump-to-location and jumper-remove-location.
;; It composes jumper--format-location (which now goes through the extracted
;; jumper--with-marker-at).  The wrappers cover it transitively; this exercises
;; it directly against stored locations.

;;; Code:

(require 'ert)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'jumper)

(ert-deftest test-jumper-location-candidates-one-pair-per-stored-location ()
  "Normal: one (display . index) pair per stored location, indices in order."
  (let ((saved-regs jumper--registers)
        (saved-idx jumper--next-index))
    (unwind-protect
        (progn
          (setq jumper--registers (make-vector jumper-max-locations nil)
                jumper--next-index 0)
          (with-temp-buffer
            (insert "line one\nline two\nline three\n")
            (goto-char (point-min))
            (should (integerp (jumper--do-store-location)))   ; index 0
            (forward-line 2)
            (should (integerp (jumper--do-store-location)))   ; index 1
            (let ((cands (jumper--location-candidates)))
              (should (= (length cands) 2))
              (should (equal (mapcar #'cdr cands) '(0 1)))
              (should (stringp (car (nth 0 cands))))
              (should (stringp (car (nth 1 cands)))))))
      (setq jumper--registers saved-regs
            jumper--next-index saved-idx))))

(ert-deftest test-jumper-location-candidates-empty-when-none-stored ()
  "Boundary: no stored locations yields an empty candidate list."
  (let ((saved-regs jumper--registers)
        (saved-idx jumper--next-index))
    (unwind-protect
        (progn
          (setq jumper--registers (make-vector jumper-max-locations nil)
                jumper--next-index 0)
          (should (null (jumper--location-candidates))))
      (setq jumper--registers saved-regs
            jumper--next-index saved-idx))))

(provide 'test-jumper--location-candidates)
;;; test-jumper--location-candidates.el ends here