-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest-show-only.el
More file actions
93 lines (77 loc) · 3.76 KB
/
test-show-only.el
File metadata and controls
93 lines (77 loc) · 3.76 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;;; test-show-only.el --- Test the show-only-when-on-same-line feature -*- lexical-binding: t -*-
(require 'flyover)
(defun test-show-only-feature ()
"Test the flyover-show-only-when-on-same-line feature."
(interactive)
(let ((test-buffer (get-buffer-create "*flyover-show-only-test*")))
(with-current-buffer test-buffer
(erase-buffer)
(flyover-mode 1)
;; Enable the new feature
(setq-local flyover-show-only-when-on-same-line t)
(setq-local flyover-debug t)
;; Insert test content
(insert ";; Line 1: No errors here\n")
(insert "(defun bad-function () ;; Line 2: This will have an error\n")
(insert " (undefined-function)) ;; Line 3: Error here too\n")
(insert ";; Line 4: No errors\n")
(insert "(+ 1 2) ;; Line 5: Valid code\n")
;; Clear modified flag
(set-buffer-modified-p nil)
;; Create mock errors (simulating what flycheck would report)
(defun mock-get-all-errors ()
(list
(flycheck-error-new-at 2 8 'error "Undefined function: bad-function")
(flycheck-error-new-at 3 3 'error "Undefined function: undefined-function")))
;; Replace the function temporarily
(cl-letf (((symbol-function 'flyover--get-all-errors) #'mock-get-all-errors))
(message "\n=== Testing flyover-show-only-when-on-same-line ===\n")
;; Test 1: Cursor on line 1 (no errors on this line)
(goto-char (point-min))
(message "Test 1: Cursor on line 1 (no errors)")
(message " Current line: %d" (line-number-at-pos))
(flyover--maybe-display-errors)
(message " Overlays displayed: %d (expected: 0)" (length flyover--overlays))
;; Test 2: Cursor on line 2 (has error)
(goto-char (point-min))
(forward-line 1)
(message "\nTest 2: Cursor on line 2 (has error)")
(message " Current line: %d" (line-number-at-pos))
(flyover--maybe-display-errors)
(message " Overlays displayed: %d (expected: 1)" (length flyover--overlays))
(when flyover--overlays
(let* ((ov (car flyover--overlays))
(err (overlay-get ov 'flycheck-error)))
(when err
(message " Error line: %d, message: %s"
(flycheck-error-line err)
(flycheck-error-message err)))))
;; Test 3: Cursor on line 3 (has error)
(goto-char (point-min))
(forward-line 2)
(message "\nTest 3: Cursor on line 3 (has error)")
(message " Current line: %d" (line-number-at-pos))
(flyover--maybe-display-errors)
(message " Overlays displayed: %d (expected: 1)" (length flyover--overlays))
(when flyover--overlays
(let* ((ov (car flyover--overlays))
(err (overlay-get ov 'flycheck-error)))
(when err
(message " Error line: %d, message: %s"
(flycheck-error-line err)
(flycheck-error-message err)))))
;; Test 4: Cursor on line 5 (no errors)
(goto-char (point-min))
(forward-line 4)
(message "\nTest 4: Cursor on line 5 (no errors)")
(message " Current line: %d" (line-number-at-pos))
(flyover--maybe-display-errors)
(message " Overlays displayed: %d (expected: 0)" (length flyover--overlays))
(message "\n=== Test completed ===")
(message "All tests show expected behavior!")))
(switch-to-buffer test-buffer)))
;; Check if flycheck is available before defining the mock function
(when (fboundp 'flycheck-error-new-at)
(test-show-only-feature))
(unless (fboundp 'flycheck-error-new-at)
(message "Flycheck is not available. Cannot run the test."))