blob: 2d6fa91670efdde5ff004f40953666eb4e46676d (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
;;; test-music-config--pin-point.el --- Tests for the playlist gutter cursor -*- coding: utf-8; lexical-binding: t; -*-
;;
;; Author: Craig Jennings <c@cjennings.net>
;;
;;; Commentary:
;; The playlist cursor lives pinned at the start of the row (the number
;; gutter). The rows are rendered track lines, not editable text, and
;; vertical motion over thumbnails and stretch-space drifts point to
;; arbitrary visual columns (usually line end). A buffer-local
;; post-command snap enforces the model for every motion command. The one
;; exception is an active isearch, which owns point placement until it ends.
;;; Code:
(require 'ert)
(require 'cl-lib)
(defvar cj/custom-keymap (make-sparse-keymap)
"Stub keymap for testing.")
(require 'music-config)
;;; Normal Cases
(ert-deftest test-music-pin-point-snaps-mid-line-to-bol ()
"Normal: point mid-row snaps back to the beginning of the line."
(with-temp-buffer
(insert "track one\ntrack two\n")
(goto-char (point-min))
(forward-char 5)
(cj/music--pin-point-to-bol)
(should (bolp))
(should (= (point) (point-min)))))
(ert-deftest test-music-pin-point-noop-at-bol ()
"Normal: point already at the row start stays put."
(with-temp-buffer
(insert "track one\ntrack two\n")
(goto-char (point-min))
(forward-line 1)
(let ((before (point)))
(cj/music--pin-point-to-bol)
(should (= (point) before)))))
;;; Boundary Cases
(ert-deftest test-music-pin-point-skips-during-isearch ()
"Boundary: an active isearch owns point; the pin defers until it ends."
(with-temp-buffer
(insert "track one\ntrack two\n")
(goto-char (point-min))
(forward-char 5)
(let ((isearch-mode t))
(cj/music--pin-point-to-bol))
(should-not (bolp))))
(ert-deftest test-music-pin-point-empty-buffer-no-error ()
"Boundary: an empty buffer is a no-op, no error."
(with-temp-buffer
(should-not (cj/music--pin-point-to-bol))
(should (bolp))))
;;; Hook wiring
(ert-deftest test-music-pin-point-ensure-wires-post-command-hook ()
"Normal: the playlist buffer gets the pin on its buffer-local
post-command-hook."
(let (created)
(cl-letf (((symbol-function 'emms-playlist-mode) #'ignore))
(unwind-protect
(progn
(setq created (cj/music--ensure-playlist-buffer))
(with-current-buffer created
(should (member #'cj/music--pin-point-to-bol post-command-hook))))
(when (buffer-live-p created) (kill-buffer created))))))
(provide 'test-music-config--pin-point)
;;; test-music-config--pin-point.el ends here
|