mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
- The documentation has the correct behavior about `linguist-detectable`: In cases where a file should be considered for language statistics, regardless of its category, the linguist-detectable attribute can be used. - This patch follows that behavior by not skipping the file even if some heuristic would've said to skip the file. - Document the conditions in more natural language. - Resolves forgejo/forgejo#11248 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11685 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRepository_GetLanguageStats(t *testing.T) {
|
|
repoPath := filepath.Join(testReposDir, "language_stats_repo")
|
|
gitRepo, err := openRepositoryWithDefaultContext(repoPath)
|
|
require.NoError(t, err)
|
|
|
|
defer gitRepo.Close()
|
|
|
|
stats, err := gitRepo.GetLanguageStats("8fee858da5796dfb37704761701bb8e800ad9ef3")
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, map[string]int64{
|
|
"Python": 134,
|
|
"Java": 112,
|
|
}, stats)
|
|
|
|
stats, err = gitRepo.GetLanguageStats("95d3505f2db273e40be79f84416051ae85e9ea0d")
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, map[string]int64{
|
|
"Cobra": 67,
|
|
"Python": 67,
|
|
"Java": 112,
|
|
}, stats)
|
|
|
|
stats, err = gitRepo.GetLanguageStats("5684d0c8cfdfb17fcd59101826efc9ff54b80df4")
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, map[string]int64{
|
|
"Cobra": 67,
|
|
"Python": 67,
|
|
"Markdown": 15,
|
|
"Java": 112,
|
|
}, stats)
|
|
}
|
|
|
|
func TestMergeLanguageStats(t *testing.T) {
|
|
assert.Equal(t, map[string]int64{
|
|
"PHP": 1,
|
|
"python": 10,
|
|
"JAVA": 700,
|
|
}, mergeLanguageStats(map[string]int64{
|
|
"PHP": 1,
|
|
"python": 10,
|
|
"Java": 100,
|
|
"java": 200,
|
|
"JAVA": 400,
|
|
}))
|
|
}
|