-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest-diff-visibility.el
More file actions
80 lines (63 loc) · 3.08 KB
/
test-diff-visibility.el
File metadata and controls
80 lines (63 loc) · 3.08 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
;;; test-diff-visibility.el --- Test script for context-aware diff hiding -*- lexical-binding: t; -*-
;; This test demonstrates the context-aware diff hiding feature
;;; Commentary:
;; This test script verifies the context-aware diff hiding functionality
;; in monet.el. It tests whether diffs are properly shown/hidden based
;; on the current buffer context.
;;; Code:
(require 'monet)
;; Enable the feature
(setq monet-hide-diff-when-irrelevant t)
(message "Testing context-aware diff hiding...")
(message "Feature enabled: %s" monet-hide-diff-when-irrelevant)
;; Create a mock session for testing
(let* ((session (make-monet--session
:key "test-session"
:directory "/Users/steve/repos/monet"
:port 12345
:initialized t
:auth-token "test-token"
:opened-diffs (make-hash-table :test 'equal)
:deferred-responses (make-hash-table :test 'equal)))
(test-buffer (get-buffer-create "*test-file*"))
(diff-buffer (get-buffer-create "*Diff: test*")))
;; Set up test buffer as if it's a file in the session directory
(with-current-buffer test-buffer
(setq buffer-file-name "/Users/steve/repos/monet/test.el"))
;; Create a mock diff context
(let ((diff-context `((diff-buffer . ,diff-buffer)
(initiating-file . "/Users/steve/repos/monet/test.el")
(session-directory . "/Users/steve/repos/monet")
(tab-name . "test-tab"))))
;; Store the diff in the session
(puthash "test-tab" diff-context (monet--session-opened-diffs session))
;; Test 1: Check if buffer is relevant to session
(message "\nTest 1: Buffer relevance check")
(message " Buffer in session dir: %s"
(monet--is-buffer-relevant-to-session-p
test-buffer
"/Users/steve/repos/monet"
"/Users/steve/repos/monet/test.el"))
;; Test 2: Check if diff should be shown
(message "\nTest 2: Should show diff check")
(message " Should show diff for test buffer: %s"
(monet--should-show-diff-p diff-context test-buffer))
;; Test 3: Check with unrelated buffer
(let ((unrelated-buffer (get-buffer-create "*unrelated*")))
(with-current-buffer unrelated-buffer
(setq buffer-file-name "/tmp/unrelated.el"))
(message "\nTest 3: Unrelated buffer check")
(message " Should show diff for unrelated buffer: %s"
(monet--should-show-diff-p diff-context unrelated-buffer)))
;; Test 4: Check with initiating file
(let ((initiating-buffer (get-buffer-create "*initiating*")))
(with-current-buffer initiating-buffer
(setq buffer-file-name "/Users/steve/repos/monet/test.el"))
(message "\nTest 4: Initiating file check")
(message " Should show diff for initiating file: %s"
(monet--should-show-diff-p diff-context initiating-buffer))))
;; Clean up
(kill-buffer test-buffer)
(kill-buffer diff-buffer))
(message "\nTest completed!")
;;; test-diff-visibility.el ends here