mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 17:56:21 +00:00
[BUG] Sort file list case insensitively
- Make the sorting done on the entries list case insensitive. - Adds integration test. - Resolves #317
This commit is contained in:
parent
d0e5af7079
commit
86b46085c7
|
@ -5,11 +5,13 @@ package base
|
|||
|
||||
import (
|
||||
"math/big"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// NaturalSortLess compares two strings so that they could be sorted in natural order
|
||||
func NaturalSortLess(s1, s2 string) bool {
|
||||
s1, s2 = strings.ToLower(s1), strings.ToLower(s2)
|
||||
var i1, i2 int
|
||||
for {
|
||||
rune1, j1, end1 := getNextRune(s1, i1)
|
||||
|
|
|
@ -20,4 +20,10 @@ func TestNaturalSortLess(t *testing.T) {
|
|||
test("a-1-a", "a-1-b", true)
|
||||
test("2", "12", true)
|
||||
test("a", "ab", true)
|
||||
|
||||
// Test for case insensitive.
|
||||
test("A", "ab", true)
|
||||
test("B", "ab", false)
|
||||
test("a", "AB", true)
|
||||
test("b", "AB", false)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package integration
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -15,11 +16,13 @@ import (
|
|||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -899,3 +902,62 @@ func TestRepoHomeViewRedirect(t *testing.T) {
|
|||
assert.Equal(t, "Wiki", txt)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRepoFilesList(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// create the repo
|
||||
repo, _, f := CreateDeclarativeRepo(t, user2, "",
|
||||
[]unit_model.Type{unit_model.TypeCode}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "zEta",
|
||||
ContentReader: strings.NewReader("zeta"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "licensa",
|
||||
ContentReader: strings.NewReader("licensa"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "licensz",
|
||||
ContentReader: strings.NewReader("licensz"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "delta",
|
||||
ContentReader: strings.NewReader("delta"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "Charlie/aa.txt",
|
||||
ContentReader: strings.NewReader("charlie"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "Beta",
|
||||
ContentReader: strings.NewReader("beta"),
|
||||
},
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "alpha",
|
||||
ContentReader: strings.NewReader("alpha"),
|
||||
},
|
||||
},
|
||||
)
|
||||
defer f()
|
||||
|
||||
req := NewRequest(t, "GET", "/"+repo.FullName())
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
filesList := htmlDoc.Find("#repo-files-table tbody tr").Map(func(_ int, s *goquery.Selection) string {
|
||||
return s.AttrOr("data-entryname", "")
|
||||
})
|
||||
|
||||
assert.EqualValues(t, []string{"Charlie", "alpha", "Beta", "delta", "licensa", "LICENSE", "licensz", "README.md", "zEta"}, filesList)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue