loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[BUG] Sort file list case insensitively

- Make the sorting done on the entries list case insensitive.
- Adds integration test.
- Resolves #317

Gusted 86b46085 d0e5af70

+70
+2
modules/base/natural_sort.go
··· 5 5 6 6 import ( 7 7 "math/big" 8 + "strings" 8 9 "unicode/utf8" 9 10 ) 10 11 11 12 // NaturalSortLess compares two strings so that they could be sorted in natural order 12 13 func NaturalSortLess(s1, s2 string) bool { 14 + s1, s2 = strings.ToLower(s1), strings.ToLower(s2) 13 15 var i1, i2 int 14 16 for { 15 17 rune1, j1, end1 := getNextRune(s1, i1)
+6
modules/base/natural_sort_test.go
··· 20 20 test("a-1-a", "a-1-b", true) 21 21 test("2", "12", true) 22 22 test("a", "ab", true) 23 + 24 + // Test for case insensitive. 25 + test("A", "ab", true) 26 + test("B", "ab", false) 27 + test("a", "AB", true) 28 + test("b", "AB", false) 23 29 }
+62
tests/integration/repo_test.go
··· 6 6 import ( 7 7 "fmt" 8 8 "net/http" 9 + "net/url" 9 10 "path" 10 11 "strings" 11 12 "testing" ··· 15 16 repo_model "code.gitea.io/gitea/models/repo" 16 17 unit_model "code.gitea.io/gitea/models/unit" 17 18 "code.gitea.io/gitea/models/unittest" 19 + user_model "code.gitea.io/gitea/models/user" 18 20 "code.gitea.io/gitea/modules/git" 19 21 "code.gitea.io/gitea/modules/setting" 20 22 "code.gitea.io/gitea/modules/test" 21 23 "code.gitea.io/gitea/modules/translation" 22 24 repo_service "code.gitea.io/gitea/services/repository" 25 + files_service "code.gitea.io/gitea/services/repository/files" 23 26 "code.gitea.io/gitea/tests" 24 27 25 28 "github.com/PuerkitoBio/goquery" ··· 899 902 assert.Equal(t, "Wiki", txt) 900 903 }) 901 904 } 905 + 906 + func TestRepoFilesList(t *testing.T) { 907 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 908 + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 909 + 910 + // create the repo 911 + repo, _, f := CreateDeclarativeRepo(t, user2, "", 912 + []unit_model.Type{unit_model.TypeCode}, nil, 913 + []*files_service.ChangeRepoFile{ 914 + { 915 + Operation: "create", 916 + TreePath: "zEta", 917 + ContentReader: strings.NewReader("zeta"), 918 + }, 919 + { 920 + Operation: "create", 921 + TreePath: "licensa", 922 + ContentReader: strings.NewReader("licensa"), 923 + }, 924 + { 925 + Operation: "create", 926 + TreePath: "licensz", 927 + ContentReader: strings.NewReader("licensz"), 928 + }, 929 + { 930 + Operation: "create", 931 + TreePath: "delta", 932 + ContentReader: strings.NewReader("delta"), 933 + }, 934 + { 935 + Operation: "create", 936 + TreePath: "Charlie/aa.txt", 937 + ContentReader: strings.NewReader("charlie"), 938 + }, 939 + { 940 + Operation: "create", 941 + TreePath: "Beta", 942 + ContentReader: strings.NewReader("beta"), 943 + }, 944 + { 945 + Operation: "create", 946 + TreePath: "alpha", 947 + ContentReader: strings.NewReader("alpha"), 948 + }, 949 + }, 950 + ) 951 + defer f() 952 + 953 + req := NewRequest(t, "GET", "/"+repo.FullName()) 954 + resp := MakeRequest(t, req, http.StatusOK) 955 + 956 + htmlDoc := NewHTMLParser(t, resp.Body) 957 + filesList := htmlDoc.Find("#repo-files-table tbody tr").Map(func(_ int, s *goquery.Selection) string { 958 + return s.AttrOr("data-entryname", "") 959 + }) 960 + 961 + assert.EqualValues(t, []string{"Charlie", "alpha", "Beta", "delta", "licensa", "LICENSE", "licensz", "README.md", "zEta"}, filesList) 962 + }) 963 + }