@@ -198,5 +198,73 @@ int divide_seventeen(int param) {
198198}
199199" )))))
200200
201+ (ert-deftest lsp-sonarlint-test--display-execution-flow ()
202+ " Test that flow steps are displayed correctly and in order."
203+ (let ((target-file-buf (find-file-noselect lsp-sonarlint-test--file-path)))
204+ (with-current-buffer target-file-buf
205+ (let* ((primary-range (lsp-sonarlint-test-range-make
206+ (buffer-string )
207+ " return 10 / param;"
208+ " ^ " ))
209+ (primary-loc `(:message " Division by 0" :range , primary-range ))
210+ (flow
211+ ; ; SonarLint sends flow in reverse order
212+ (list
213+ ; ; SonarLint often duplicates primary message in a flow step
214+ primary-loc
215+ `(:message " Assigning a 0"
216+ :range
217+ ,(lsp-sonarlint-test-range-make (buffer-string )
218+ " int a = 0;"
219+ " ^^^^^ " ))
220+ `(:message " Taking true branch"
221+ :range
222+ ,(lsp-sonarlint-test-range-make (buffer-string )
223+ " if (param == 0) {"
224+ " ^^ " ))
225+ `(:message " Assuming param is 0"
226+ :range
227+ ,(lsp-sonarlint-test-range-make (buffer-string )
228+ " if (param == 0) {"
229+ " ^^^^ " ))
230+ `(:message " Evaluating condition"
231+ :range
232+ ,(lsp-sonarlint-test-range-make (buffer-string )
233+ " if (param == 0) {"
234+ " ^^^^^^^^^^ " ))))
235+ (command (lsp-sonarlint-test--secloc-command
236+ primary-loc (list flow))))
237+ (message " cmd : %s " command)
238+ (lsp-sonarlint--show-all-locations command)))
239+ (with-current-buffer lsp-sonarlint--secondary-messages-buffer-name
240+ (should (equal (lsp-sonarlint-test--buf-string-with-overlay-strings)
241+ " Division by 0
242+ 1Evaluating condition
243+ 2Assuming param is 0
244+ 3Taking true branch
245+ 4Assigning a 0
246+ 5Division by 0" )))
247+ (with-current-buffer target-file-buf
248+ ; ; In-line messages appear shifted here because they are rendered
249+ ; ; with the same font.
250+ ; ; In the actual buffer these strings have smaller font, so
251+ ; ; they start closer to the left.
252+ (should (equal (lsp-sonarlint-test--buf-string-with-overlay-strings)
253+ "
254+ int divide_seventeen(int param) {
255+ Taking true branch
256+ Evaluating condition
257+ 3if (1param 2== 0) {
258+ Assuming param is 0
259+ Assigning a 0
260+ int 4a = 0;
261+ } else {
262+ int b = 0;
263+ }
264+ Division by 0
265+ return 10 5/ param;
266+ }
267+ " )))))
268+
201269
202270; ;; lsp-sonarlint-secondar-locations-test.el ends here
0 commit comments