Skip to content

Commit 7bf93e5

Browse files
author
Gusted
committed
Merge pull request 'A new test to exercise linguist-language=' (go-gitea#2368) from algernon/tests/linguist/view-guess into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2368 Reviewed-by: Gusted <[email protected]> Reviewed-by: Otto <[email protected]>
2 parents fd01298 + ae95db1 commit 7bf93e5

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/integration/repo_lang_stats_test.go renamed to tests/integration/linguist_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"context"
8+
"net/http"
89
"net/url"
910
"strings"
1011
"testing"
@@ -22,7 +23,7 @@ import (
2223
"github.com/stretchr/testify/assert"
2324
)
2425

25-
func TestRepoLangStats(t *testing.T) {
26+
func TestLinguistSupport(t *testing.T) {
2627
onGiteaRun(t, func(t *testing.T, u *url.URL) {
2728
/******************
2829
** Preparations **
@@ -219,5 +220,36 @@ func TestRepoLangStats(t *testing.T) {
219220
langs := getFreshLanguageStats(t, repo, sha)
220221
assert.Empty(t, langs)
221222
})
223+
224+
// 9. Overriding the language
225+
t.Run("linguist-language", func(t *testing.T) {
226+
defer tests.PrintCurrentTest(t)()
227+
228+
repo, _, f := prep(t, "foo.c linguist-language=sh\n")
229+
defer f()
230+
231+
assertFileLanguage := func(t *testing.T, uri, expectedLanguage string) {
232+
t.Helper()
233+
234+
req := NewRequest(t, "GET", repo.Link()+uri)
235+
resp := MakeRequest(t, req, http.StatusOK)
236+
htmlDoc := NewHTMLParser(t, resp.Body)
237+
238+
language := strings.TrimSpace(htmlDoc.Find(".file-info .file-info-entry:nth-child(3)").Text())
239+
assert.Equal(t, expectedLanguage, language)
240+
}
241+
242+
t.Run("file source view", func(t *testing.T) {
243+
defer tests.PrintCurrentTest(t)()
244+
245+
assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash")
246+
})
247+
248+
t.Run("file blame view", func(t *testing.T) {
249+
defer tests.PrintCurrentTest(t)()
250+
251+
assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash")
252+
})
253+
})
222254
})
223255
}

0 commit comments

Comments
 (0)