-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cr_actions_test.go
102 lines (87 loc) · 2.71 KB
/
cr_actions_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libkbfs
import (
"reflect"
"testing"
"github.com/keybase/client/go/kbfs/data"
)
func testPPS(s string) data.PathPartString {
return data.NewPathPartString(s, nil)
}
func TestCRActionsCollapseNoChange(t *testing.T) {
al := crActionList{
©UnmergedEntryAction{
testPPS("old1"), testPPS("new1"), testPPS(""), false, false,
data.DirEntry{}, nil},
©UnmergedEntryAction{
testPPS("old2"), testPPS("new2"), testPPS(""), false, false,
data.DirEntry{}, nil},
&renameUnmergedAction{
testPPS("old3"), testPPS("new3"), testPPS(""), 0, false,
data.ZeroPtr, data.ZeroPtr},
&renameMergedAction{testPPS("old4"), testPPS("new4"), testPPS("")},
©UnmergedAttrAction{
testPPS("old5"), testPPS("new5"), []attrChange{mtimeAttr}, false},
}
newList := al.collapse()
if !reflect.DeepEqual(al, newList) {
t.Errorf("Collapse returned different list: %v vs %v", al, newList)
}
}
func TestCRActionsCollapseEntry(t *testing.T) {
al := crActionList{
©UnmergedAttrAction{
testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
©UnmergedEntryAction{
testPPS("old"), testPPS("new"), testPPS(""), false, false,
data.DirEntry{}, nil},
&renameUnmergedAction{
testPPS("old"), testPPS("new"), testPPS(""), 0, false, data.ZeroPtr,
data.ZeroPtr},
}
expected := crActionList{
al[2],
}
newList := al.collapse()
if !reflect.DeepEqual(expected, newList) {
t.Errorf("Collapse returned unexpected list: %v vs %v",
expected, newList)
}
// change the order
al = crActionList{al[1], al[2], al[0]}
newList = al.collapse()
if !reflect.DeepEqual(expected, newList) {
t.Errorf("Collapse returned unexpected list: %v vs %v",
expected, newList)
}
// Omit the top action this time
al = crActionList{al[0], al[2]}
expected = crActionList{al[0]}
newList = al.collapse()
if !reflect.DeepEqual(expected, newList) {
t.Errorf("Collapse returned unexpected list: %v vs %v",
expected, newList)
}
}
func TestCRActionsCollapseAttr(t *testing.T) {
al := crActionList{
©UnmergedAttrAction{
testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
©UnmergedAttrAction{
testPPS("old"), testPPS("new"), []attrChange{exAttr}, false},
©UnmergedAttrAction{
testPPS("old"), testPPS("new"), []attrChange{mtimeAttr}, false},
}
expected := crActionList{
©UnmergedAttrAction{
testPPS("old"), testPPS("new"), []attrChange{mtimeAttr, exAttr},
false},
}
newList := al.collapse()
if !reflect.DeepEqual(expected, newList) {
t.Errorf("Collapse returned unexpected list: %v vs %v",
expected, newList)
}
}