forked from go-gitea/git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_entry_test.go
52 lines (46 loc) · 1.58 KB
/
tree_entry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func getTestEntries() Entries {
return Entries{
&TreeEntry{name: "v1.0", mode: EntryModeTree},
&TreeEntry{name: "v2.0", mode: EntryModeTree},
&TreeEntry{name: "v2.1", mode: EntryModeTree},
&TreeEntry{name: "v2.12", mode: EntryModeTree},
&TreeEntry{name: "v2.2", mode: EntryModeTree},
&TreeEntry{name: "v12.0", mode: EntryModeTree},
&TreeEntry{name: "abc", mode: EntryModeBlob},
&TreeEntry{name: "bcd", mode: EntryModeBlob},
}
}
func TestEntriesSort(t *testing.T) {
entries := getTestEntries()
entries.Sort()
assert.Equal(t, "v1.0", entries[0].Name())
assert.Equal(t, "v12.0", entries[1].Name())
assert.Equal(t, "v2.0", entries[2].Name())
assert.Equal(t, "v2.1", entries[3].Name())
assert.Equal(t, "v2.12", entries[4].Name())
assert.Equal(t, "v2.2", entries[5].Name())
assert.Equal(t, "abc", entries[6].Name())
assert.Equal(t, "bcd", entries[7].Name())
}
func TestEntriesCustomSort(t *testing.T) {
entries := getTestEntries()
entries.CustomSort(func(s1, s2 string) bool {
return s1 > s2
})
assert.Equal(t, "v2.2", entries[0].Name())
assert.Equal(t, "v2.12", entries[1].Name())
assert.Equal(t, "v2.1", entries[2].Name())
assert.Equal(t, "v2.0", entries[3].Name())
assert.Equal(t, "v12.0", entries[4].Name())
assert.Equal(t, "v1.0", entries[5].Name())
assert.Equal(t, "bcd", entries[6].Name())
assert.Equal(t, "abc", entries[7].Name())
}