|
354 | 354 | "Test git-link-homepage-codecommit function." |
355 | 355 | (should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse" |
356 | 356 | (git-link-homepage-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo")))) |
| 357 | + |
| 358 | +(ert-deftest git-link-interactive-simulation () |
| 359 | + "Test interactive git-link function call with cursor at line 3." |
| 360 | + (with-temp-buffer |
| 361 | + ;; Set up buffer content |
| 362 | + (insert "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n") |
| 363 | + (goto-char (point-min)) |
| 364 | + (forward-line 2) ; Move to line 3 |
| 365 | + |
| 366 | + ;; Mock git repository context |
| 367 | + (let ((buffer-file-name "/tmp/test-repo/file.txt") |
| 368 | + (default-directory "/tmp/test-repo/") |
| 369 | + git-link-add-to-kill-ring ; Don't add to kill ring during test |
| 370 | + git-link-open-in-browser) ; Don't open browser during test |
| 371 | + |
| 372 | + ;; Mock git functions to return expected values |
| 373 | + (cl-letf (((symbol-function 'git-link--remote-url) |
| 374 | + (lambda (_remote) "https://github.com/user/repo.git")) |
| 375 | + ((symbol-function 'git-link--relative-filename) |
| 376 | + (lambda () "file.txt")) |
| 377 | + ((symbol-function 'git-link--branch) |
| 378 | + (lambda () "master")) |
| 379 | + ((symbol-function 'git-link--commit) |
| 380 | + (lambda () "abc123")) |
| 381 | + ((symbol-function 'git-link--repo-root) |
| 382 | + (lambda () "/tmp/test-repo")) |
| 383 | + ((symbol-function 'git-link--remote) |
| 384 | + (lambda () "origin")) |
| 385 | + ((symbol-function 'git-link--new) |
| 386 | + (lambda (url) url))) ; Return URL directly instead of processing it |
| 387 | + |
| 388 | + ;; Call git-link interactively |
| 389 | + (let ((result (git-link "origin" 3 nil))) ; Line 3, no end line |
| 390 | + ;; Verify the result contains GitHub URL with line number |
| 391 | + (should (stringp result)) |
| 392 | + (should (string-match-p "github\\.com" result)) |
| 393 | + (should (string-match-p "file\\.txt" result)) |
| 394 | + (should (string-match-p "#L3" result))))))) |
0 commit comments