Skip to content

Commit e5b891a

Browse files
Copilotsshaw
andcommitted
Add comprehensive tests for all git-link functions
Co-authored-by: sshaw <17570+sshaw@users.noreply.github.com>
1 parent 270a9d1 commit e5b891a

File tree

1 file changed

+226
-0
lines changed

1 file changed

+226
-0
lines changed

git-link-test.el

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,170 @@
126126
(should (equal "https://bitbucket.org"
127127
(git-link--web-host "bitbucket.org")))))
128128

129+
(ert-deftest git-link-github ()
130+
"Test git-link-github function."
131+
;; Basic file link with branch
132+
(should (equal "https://github.com/user/repo/blob/master/file.txt"
133+
(git-link-github "https://github.com" "user/repo" "file.txt" "master" "abc123" nil nil)))
134+
135+
;; File link with single line number
136+
(should (equal "https://github.com/user/repo/blob/master/file.txt#L10"
137+
(git-link-github "https://github.com" "user/repo" "file.txt" "master" "abc123" 10 nil)))
138+
139+
;; File link with line range
140+
(should (equal "https://github.com/user/repo/blob/master/file.txt#L10-L20"
141+
(git-link-github "https://github.com" "user/repo" "file.txt" "master" "abc123" 10 20)))
142+
143+
;; File link with commit instead of branch
144+
(should (equal "https://github.com/user/repo/blob/abc123/file.txt"
145+
(git-link-github "https://github.com" "user/repo" "file.txt" nil "abc123" nil nil)))
146+
147+
;; Test with custom scheme
148+
(should (equal "http://internal.github.com/user/repo/blob/master/file.txt"
149+
(git-link-github "http://internal.github.com" "user/repo" "file.txt" "master" "abc123" nil nil))))
150+
151+
(ert-deftest git-link-gitlab ()
152+
"Test git-link-gitlab function."
153+
;; Basic file link with branch
154+
(should (equal "https://gitlab.com/user/repo/-/blob/master/file.txt"
155+
(git-link-gitlab "https://gitlab.com" "user/repo" "file.txt" "master" "abc123" nil nil)))
156+
157+
;; File link with single line number
158+
(should (equal "https://gitlab.com/user/repo/-/blob/master/file.txt#L10"
159+
(git-link-gitlab "https://gitlab.com" "user/repo" "file.txt" "master" "abc123" 10 nil)))
160+
161+
;; File link with line range
162+
(should (equal "https://gitlab.com/user/repo/-/blob/master/file.txt#L10-20"
163+
(git-link-gitlab "https://gitlab.com" "user/repo" "file.txt" "master" "abc123" 10 20)))
164+
165+
;; File link with commit instead of branch
166+
(should (equal "https://gitlab.com/user/repo/-/blob/abc123/file.txt"
167+
(git-link-gitlab "https://gitlab.com" "user/repo" "file.txt" nil "abc123" nil nil))))
168+
169+
(ert-deftest git-link-codeberg ()
170+
"Test git-link-codeberg function."
171+
;; Basic file link with branch
172+
(should (equal "https://codeberg.org/user/repo/src/master/file.txt"
173+
(git-link-codeberg "https://codeberg.org" "user/repo" "file.txt" "master" "abc123" nil nil)))
174+
175+
;; File link with single line number
176+
(should (equal "https://codeberg.org/user/repo/src/master/file.txt#L10"
177+
(git-link-codeberg "https://codeberg.org" "user/repo" "file.txt" "master" "abc123" 10 nil)))
178+
179+
;; File link with line range
180+
(should (equal "https://codeberg.org/user/repo/src/master/file.txt#L10-L20"
181+
(git-link-codeberg "https://codeberg.org" "user/repo" "file.txt" "master" "abc123" 10 20)))
182+
183+
;; File link with commit instead of branch
184+
(should (equal "https://codeberg.org/user/repo/src/abc123/file.txt"
185+
(git-link-codeberg "https://codeberg.org" "user/repo" "file.txt" nil "abc123" nil nil))))
186+
187+
(ert-deftest git-link-gitorious ()
188+
"Test git-link-gitorious function."
189+
;; File link with commit and line number
190+
(should (equal "https://gitorious.org/user/repo/source/abc123:file.txt#L10"
191+
(git-link-gitorious "https://gitorious.org" "user/repo" "file.txt" "master" "abc123" 10 nil))))
192+
193+
(ert-deftest git-link-savannah ()
194+
"Test git-link-savannah function."
195+
;; Basic file link with branch
196+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=master"
197+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" "master" "abc123" nil nil)))
198+
199+
;; File link with single line number
200+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=master#n10"
201+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" "master" "abc123" 10 nil)))
202+
203+
;; File link with commit instead of branch
204+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=abc123"
205+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" nil "abc123" nil nil))))
206+
207+
(ert-deftest git-link-googlesource ()
208+
"Test git-link-googlesource function."
209+
;; Basic file link with branch
210+
(should (equal "https://go.googlesource.com/go/+/master/file.txt"
211+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" "master" "abc123" nil nil)))
212+
213+
;; File link with single line number
214+
(should (equal "https://go.googlesource.com/go/+/master/file.txt#10"
215+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" "master" "abc123" 10 nil)))
216+
217+
;; File link with commit instead of branch
218+
(should (equal "https://go.googlesource.com/go/+/abc123/file.txt"
219+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" nil "abc123" nil nil))))
220+
221+
(ert-deftest git-link-azure ()
222+
"Test git-link-azure function."
223+
;; Basic file link with branch
224+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=&lineEnd=&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
225+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" nil nil)))
226+
227+
;; File link with single line number
228+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=10&lineEnd=10&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
229+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" 10 nil)))
230+
231+
;; File link with line range
232+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=10&lineEnd=20&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
233+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" 10 20)))
234+
235+
;; File link with commit instead of branch
236+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GCabc123&line=&lineEnd=&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
237+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" nil "abc123" nil nil))))
238+
239+
(ert-deftest git-link-sourcehut ()
240+
"Test git-link-sourcehut function."
241+
;; Basic file link with branch
242+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt"
243+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" nil nil)))
244+
245+
;; File link with single line number
246+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt#L10"
247+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" 10 nil)))
248+
249+
;; File link with line range
250+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt#L10-20"
251+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" 10 20)))
252+
253+
;; File link with commit instead of branch
254+
(should (equal "https://git.sr.ht/~user/repo/tree/abc123/file.txt"
255+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" nil "abc123" nil nil))))
256+
257+
(ert-deftest git-link-sourcegraph ()
258+
"Test git-link-sourcegraph function."
259+
;; Basic file link with branch
260+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt"
261+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" nil nil)))
262+
263+
;; File link with single line number
264+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt#L10"
265+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" 10 nil)))
266+
267+
;; File link with line range
268+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt#L10-20"
269+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" 10 20)))
270+
271+
;; File link with commit instead of branch
272+
(should (equal "https://sourcegraph.com/user/repo@abc123/-/blob/file.txt"
273+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" nil "abc123" nil nil))))
274+
275+
(ert-deftest git-link-codecommit ()
276+
"Test git-link-codecommit function."
277+
;; Basic file link with branch
278+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt"
279+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" nil nil)))
280+
281+
;; File link with single line number
282+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt?lines=10-10"
283+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" 10 nil)))
284+
285+
;; File link with line range
286+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt?lines=10-20"
287+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" 10 20)))
288+
289+
;; File link with commit instead of branch
290+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/abc123/--/file.txt"
291+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" nil "abc123" nil nil))))
292+
129293
(ert-deftest git-link-integration-test ()
130294
"Test that handler functions work with URL schemes from git-link--web-host."
131295

@@ -136,3 +300,65 @@
136300
;; Test GitHub handler with custom scheme
137301
(should (equal "http://internal.github.com/user/repo/blob/master/file.txt"
138302
(git-link-github "http://internal.github.com" "user/repo" "file.txt" "master" "abc123" nil nil))))
303+
304+
;; Tests for commit functions
305+
(ert-deftest git-link-commit-github ()
306+
"Test git-link-commit-github function."
307+
(should (equal "https://github.com/user/repo/commit/abc123"
308+
(git-link-commit-github "https://github.com" "user/repo" "abc123"))))
309+
310+
(ert-deftest git-link-commit-bitbucket ()
311+
"Test git-link-commit-bitbucket function."
312+
(should (equal "https://bitbucket.org/user/repo/commits/abc123"
313+
(git-link-commit-bitbucket "https://bitbucket.org" "user/repo" "abc123"))))
314+
315+
(ert-deftest git-link-commit-gitlab ()
316+
"Test git-link-commit-gitlab function."
317+
(should (equal "https://gitlab.com/user/repo/-/commit/abc123"
318+
(git-link-commit-gitlab "https://gitlab.com" "user/repo" "abc123"))))
319+
320+
(ert-deftest git-link-commit-codeberg ()
321+
"Test git-link-commit-codeberg function."
322+
(should (equal "https://codeberg.org/user/repo/commit/abc123"
323+
(git-link-commit-codeberg "https://codeberg.org" "user/repo" "abc123"))))
324+
325+
(ert-deftest git-link-commit-gitorious ()
326+
"Test git-link-commit-gitorious function."
327+
(should (equal "https://gitorious.org/user/repo/commit/abc123"
328+
(git-link-commit-gitorious "https://gitorious.org" "user/repo" "abc123"))))
329+
330+
(ert-deftest git-link-commit-savannah ()
331+
"Test git-link-commit-savannah function."
332+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/commit/?id=abc123"
333+
(git-link-commit-savannah "https://git.savannah.gnu.org" "repo" "abc123"))))
334+
335+
(ert-deftest git-link-commit-googlesource ()
336+
"Test git-link-commit-googlesource function."
337+
(should (equal "https://go.googlesource.com/go/+/abc123"
338+
(git-link-commit-googlesource "https://go.googlesource.com" "go" "abc123"))))
339+
340+
(ert-deftest git-link-commit-sourcegraph ()
341+
"Test git-link-commit-sourcegraph function."
342+
(should (equal "https://sourcegraph.com/user/repo/-/commit/abc123"
343+
(git-link-commit-sourcegraph "https://sourcegraph.com" "user/repo" "abc123"))))
344+
345+
(ert-deftest git-link-commit-codecommit ()
346+
"Test git-link-commit-codecommit function."
347+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/commit/abc123"
348+
(git-link-commit-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "abc123"))))
349+
350+
;; Tests for homepage functions
351+
(ert-deftest git-link-homepage-github ()
352+
"Test git-link-homepage-github function."
353+
(should (equal "https://github.com/user/repo"
354+
(git-link-homepage-github "https://github.com" "user/repo"))))
355+
356+
(ert-deftest git-link-homepage-savannah ()
357+
"Test git-link-homepage-savannah function."
358+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/"
359+
(git-link-homepage-savannah "https://git.savannah.gnu.org" "repo"))))
360+
361+
(ert-deftest git-link-homepage-codecommit ()
362+
"Test git-link-homepage-codecommit function."
363+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse"
364+
(git-link-homepage-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo"))))

0 commit comments

Comments
 (0)