Skip to content

Commit ae95db1

Browse files
committed
A new test to exercise linguist-language=
Rename `repo_lang_stats_test.go` to `linguist_test.go`, and add a new tests that exercises parts of the web UI to ensure that language overrides in `.gitattributes` work when viewing a file source, and in the blame view too. Signed-off-by: Gergely Nagy <[email protected]>
1 parent 28b5e39 commit ae95db1

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)