Merge pull request 'A new test to exercise linguist-language=' (#2368) from algernon/tests/linguist/view-guess into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2368
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Gusted 2024-02-17 13:46:43 +00:00
commit 7bf93e5d1a

View file

@ -5,6 +5,7 @@ package integration
import ( import (
"context" "context"
"net/http"
"net/url" "net/url"
"strings" "strings"
"testing" "testing"
@ -22,7 +23,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestRepoLangStats(t *testing.T) { func TestLinguistSupport(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) { onGiteaRun(t, func(t *testing.T, u *url.URL) {
/****************** /******************
** Preparations ** ** Preparations **
@ -219,5 +220,36 @@ func TestRepoLangStats(t *testing.T) {
langs := getFreshLanguageStats(t, repo, sha) langs := getFreshLanguageStats(t, repo, sha)
assert.Empty(t, langs) 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")
})
})
}) })
} }