diff --git a/tests/integration/repo_lang_stats_test.go b/tests/integration/linguist_test.go similarity index 87% rename from tests/integration/repo_lang_stats_test.go rename to tests/integration/linguist_test.go index 3cc924c81..12f12f5cb 100644 --- a/tests/integration/repo_lang_stats_test.go +++ b/tests/integration/linguist_test.go @@ -5,6 +5,7 @@ package integration import ( "context" + "net/http" "net/url" "strings" "testing" @@ -22,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRepoLangStats(t *testing.T) { +func TestLinguistSupport(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { /****************** ** Preparations ** @@ -219,5 +220,36 @@ func TestRepoLangStats(t *testing.T) { langs := getFreshLanguageStats(t, repo, sha) assert.Empty(t, langs) }) + + // 9. Overriding the language + t.Run("linguist-language", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + repo, _, f := prep(t, "foo.c linguist-language=sh\n") + defer f() + + assertFileLanguage := func(t *testing.T, uri, expectedLanguage string) { + t.Helper() + + req := NewRequest(t, "GET", repo.Link()+uri) + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + language := strings.TrimSpace(htmlDoc.Find(".file-info .file-info-entry:nth-child(3)").Text()) + assert.Equal(t, expectedLanguage, language) + } + + t.Run("file source view", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash") + }) + + t.Run("file blame view", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash") + }) + }) }) }