-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathorder_test.go
53 lines (45 loc) · 913 Bytes
/
order_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
53
package query
import (
"strings"
"testing"
)
func testKeyOrder(t *testing.T, f Order, keys []string, expect []string) {
e := make([]Entry, len(keys))
for i, k := range keys {
e[i] = Entry{Key: k}
}
res := ResultsWithEntries(Query{}, e)
res = NaiveOrder(res, f)
actualE, err := res.Rest()
if err != nil {
t.Fatal(err)
}
actual := make([]string, len(actualE))
for i, e := range actualE {
actual[i] = e.Key
}
if len(actual) != len(expect) {
t.Error("expect != actual.", expect, actual)
}
if strings.Join(actual, "") != strings.Join(expect, "") {
t.Error("expect != actual.", expect, actual)
}
}
func TestOrderByKey(t *testing.T) {
testKeyOrder(t, OrderByKey{}, sampleKeys, []string{
"/a",
"/ab",
"/ab/c",
"/ab/cd",
"/abce",
"/abcf",
})
testKeyOrder(t, OrderByKeyDescending{}, sampleKeys, []string{
"/abcf",
"/abce",
"/ab/cd",
"/ab/c",
"/ab",
"/a",
})
}