@@ -253,6 +253,51 @@ int divide_seventeen(int param) {
253253}
254254" )))))
255255
256+ (defun lsp-sonarlint-test--select-message (msg )
257+ " Select the step with message MSG in the SonarLint secondary messages buffer."
258+ (with-current-buffer lsp-sonarlint--secondary-messages-buffer-name
259+ (goto-char (point-min ))
260+ (search-forward msg)
261+ ; ; Deliberately using interactive functions here to trigger line-move
262+ ; ; hooks
263+ (previous-line )
264+ (next-line )))
265+
266+ (ert-deftest lsp-sonarlint-test--navigate-to-sec-location ()
267+ " Test that point moves to locations of selected messages."
268+ (let ((target-file-buf (find-file-noselect lsp-sonarlint-test--file-path)))
269+ (with-current-buffer target-file-buf
270+ (let* ((primary-range (lsp-sonarlint-test-range-make
271+ (buffer-string )
272+ " if (param == 0) {"
273+ " ^^ " ))
274+ (primary-loc `(:message " Redundant branching" :range , primary-range ))
275+ (secondary-range1
276+ (lsp-sonarlint-test-range-make (buffer-string )
277+ " int a = 0;"
278+ " ^^^^^^^^^^" ))
279+ (sec-flow1 `((:message " Code A" :range , secondary-range1 )))
280+ (secondary-range2
281+ (lsp-sonarlint-test-range-make (buffer-string )
282+ " int b = 0;"
283+ " ^^^^^^^^^^" ))
284+ (sec-flow2 `((:message " Code B" :range , secondary-range2 )))
285+ (command (lsp-sonarlint-test--secloc-command
286+ primary-loc (list sec-flow1 sec-flow2))))
287+ (lsp-sonarlint--show-all-locations command)))
288+ (with-current-buffer target-file-buf
289+ (goto-char (point-min )))
290+ (lsp-sonarlint-test--select-message " Code A" )
291+ (with-current-buffer target-file-buf
292+ (should (equal (buffer-substring-no-properties (line-beginning-position )
293+ (line-end-position ))
294+ " int a = 0;" )))
295+ (lsp-sonarlint-test--select-message " Code B" )
296+ (with-current-buffer target-file-buf
297+ (should (equal (buffer-substring-no-properties (line-beginning-position )
298+ (line-end-position ))
299+ " int b = 0;" )))))
300+
256301(ert-deftest lsp-sonarlint-test--display-execution-flow ()
257302 " Test that flow steps are displayed correctly and in order."
258303 (let ((target-file-buf (find-file-noselect lsp-sonarlint-test--file-path)))
0 commit comments