Skip to content

Commit d1cd4d9

Browse files
Copilotsshaw
andcommitted
Add comprehensive tests for all git-link functions
Co-authored-by: sshaw <[email protected]>
1 parent 5d07efd commit d1cd4d9

File tree

1 file changed

+218
-0
lines changed

1 file changed

+218
-0
lines changed

git-link-test.el

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,165 @@
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+
188+
(ert-deftest git-link-savannah ()
189+
"Test git-link-savannah function."
190+
;; Basic file link with branch
191+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=master"
192+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" "master" "abc123" nil nil)))
193+
194+
;; File link with single line number
195+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=master#n10"
196+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" "master" "abc123" 10 nil)))
197+
198+
;; File link with commit instead of branch
199+
(should (equal "https://git.savannah.gnu.org/cgit/repo.git/tree/file.txt?h=abc123"
200+
(git-link-savannah "https://git.savannah.gnu.org" "repo" "file.txt" nil "abc123" nil nil))))
201+
202+
(ert-deftest git-link-googlesource ()
203+
"Test git-link-googlesource function."
204+
;; Basic file link with branch
205+
(should (equal "https://go.googlesource.com/go/+/master/file.txt"
206+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" "master" "abc123" nil nil)))
207+
208+
;; File link with single line number
209+
(should (equal "https://go.googlesource.com/go/+/master/file.txt#10"
210+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" "master" "abc123" 10 nil)))
211+
212+
;; File link with commit instead of branch
213+
(should (equal "https://go.googlesource.com/go/+/abc123/file.txt"
214+
(git-link-googlesource "https://go.googlesource.com" "go" "file.txt" nil "abc123" nil nil))))
215+
216+
(ert-deftest git-link-azure ()
217+
"Test git-link-azure function."
218+
;; Basic file link with branch
219+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=&lineEnd=&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
220+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" nil nil)))
221+
222+
;; File link with single line number
223+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=10&lineEnd=10&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
224+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" 10 nil)))
225+
226+
;; File link with line range
227+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GBmaster&line=10&lineEnd=20&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
228+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" "master" "abc123" 10 20)))
229+
230+
;; File link with commit instead of branch
231+
(should (equal "https://dev.azure.com/project/_git/repo?path=%2Ffile.txt&version=GCabc123&line=&lineEnd=&lineStartColumn=1&lineEndColumn=9999&lineStyle=plain"
232+
(git-link-azure "https://dev.azure.com" "project/_git/repo" "file.txt" nil "abc123" nil nil))))
233+
234+
(ert-deftest git-link-sourcehut ()
235+
"Test git-link-sourcehut function."
236+
;; Basic file link with branch
237+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt"
238+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" nil nil)))
239+
240+
;; File link with single line number
241+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt#L10"
242+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" 10 nil)))
243+
244+
;; File link with line range
245+
(should (equal "https://git.sr.ht/~user/repo/tree/master/file.txt#L10-20"
246+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" "master" "abc123" 10 20)))
247+
248+
;; File link with commit instead of branch
249+
(should (equal "https://git.sr.ht/~user/repo/tree/abc123/file.txt"
250+
(git-link-sourcehut "https://git.sr.ht" "~user/repo" "file.txt" nil "abc123" nil nil))))
251+
252+
(ert-deftest git-link-sourcegraph ()
253+
"Test git-link-sourcegraph function."
254+
;; Basic file link with branch
255+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt"
256+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" nil nil)))
257+
258+
;; File link with single line number
259+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt#L10"
260+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" 10 nil)))
261+
262+
;; File link with line range
263+
(should (equal "https://sourcegraph.com/user/repo@master/-/blob/file.txt#L10-20"
264+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" "master" "abc123" 10 20)))
265+
266+
;; File link with commit instead of branch
267+
(should (equal "https://sourcegraph.com/user/repo@abc123/-/blob/file.txt"
268+
(git-link-sourcegraph "https://sourcegraph.com" "user/repo" "file.txt" nil "abc123" nil nil))))
269+
270+
(ert-deftest git-link-codecommit ()
271+
"Test git-link-codecommit function."
272+
;; Basic file link with branch
273+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt"
274+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" nil nil)))
275+
276+
;; File link with single line number
277+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt?lines=10-10"
278+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" 10 nil)))
279+
280+
;; File link with line range
281+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/master/--/file.txt?lines=10-20"
282+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" "master" "abc123" 10 20)))
283+
284+
;; File link with commit instead of branch
285+
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse/refs/heads/abc123/--/file.txt"
286+
(git-link-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo" "file.txt" nil "abc123" nil nil))))
287+
129288
(ert-deftest git-link-integration-test ()
130289
"Test that handler functions work with URL schemes from git-link--web-host."
131290

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

0 commit comments

Comments
 (0)