/ test / test-lsp-mode-mock.el
test-lsp-mode-mock.el
 1  ;;; test-lsp-mode-mock.el --- Mock test for lsp-mode integration -*- lexical-binding: t -*-
 2  
 3  (require 'code-action-quick)
 4  
 5  ;; Mock lsp-mode feature
 6  (provide 'lsp-mode)
 7  
 8  ;; Mock lsp-mode functions for testing
 9  (defvar lsp--mock-actions nil)
10  
11  (defun lsp-workspaces () (list 'mock-workspace))
12  
13  (defun lsp-code-actions-at-point ()
14    lsp--mock-actions)
15  
16  (defun lsp:code-action-title (action)
17    (plist-get action :title))
18  
19  (defun lsp:code-action-kind (action)
20    (plist-get action :kind))
21  
22  (defun lsp:code-action-is-preferred (action)
23    (plist-get action :isPreferred))
24  
25  ;; Set up mock actions
26  (setq lsp--mock-actions
27        (list 
28          (list :title "Import json" :kind "quickfix" :isPreferred t)
29          (list :title "Organize imports" :kind "source.organizeImports")
30          (list :title "Extract variable" :kind "refactor.extract")))
31  
32  ;; Test
33  (setq caq-debug t)
34  (with-temp-buffer
35    (insert "test content")
36    (goto-char 5)
37    ;; Enable lsp-mode in buffer (mock)
38    (setq-local lsp-mode t)
39    ;; Clear any cached detection
40    (setq-local caq--detected-client nil)
41    
42    (princ "=== LSP-MODE MOCK TEST ===\n")
43    (princ (format "Detected client: %s\n" (caq--detect-lsp-client)))
44    (princ "\n")
45    
46    ;; Test raw retrieval
47    (let ((raw (caq--get-actions-lsp-mode (point) (point))))
48      (princ (format "Raw actions: %d\n" (length raw)))
49      (dolist (a raw)
50        (princ (format "  [%s] %s\n" (plist-get a :kind) (plist-get a :title)))))
51    
52    (princ "\n")
53    
54    ;; Test full collection
55    (let* ((result (caq--collect-all-actions))
56           (allowed (plist-get result :allowed))
57           (rejected (plist-get result :rejected)))
58      (princ (format "Allowed: %d\n" (length allowed)))
59      (dolist (a allowed)
60        (princ (format "  OK [%s] %s\n" (caq-action-kind a) (caq-action-title a))))
61      (princ (format "Rejected: %d\n" (length rejected)))
62      (dolist (r rejected)
63        (princ (format "  NO %s - %s\n" (caq-action-title (car r)) (cdr r)))))
64    
65    (princ "\n")
66    (princ "=== SUCCESS ===\n")
67    
68    ;; Test code-action-quick command
69    (princ "\n=== Testing code-action-quick command ===\n")
70    (setq caq-execute-only-single nil)
71    
72    ;; Mock the execution
73    (defvar test-executed-action nil)
74    (defun lsp-execute-code-action (action)
75      (setq test-executed-action action)
76      (princ (format "EXECUTED: %s\n" (plist-get action :title))))
77    
78    (code-action-quick)
79    
80    (if test-executed-action
81        (princ (format "Action executed successfully: %s\n" 
82                       (plist-get test-executed-action :title)))
83      (princ "ERROR: No action was executed!\n")))
84  
85  (provide 'test-lsp-mode-mock)
86  ;;; test-lsp-mode-mock.el ends here