-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdepth_test.go
51 lines (49 loc) · 1.27 KB
/
depth_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
package find
import (
"path/filepath"
"testing"
)
func TestDepth(t *testing.T) {
sep := string(filepath.Separator)
testCases := []struct {
root string
path string
expected int
}{
{
root: "",
path: "",
expected: 0,
},
{
root: "",
path: filepath.Join("foo", "bar", "baz", "a", "b", "c"),
expected: 6,
},
{
root: "",
path: filepath.Join("foo", "bar", "baz", "a", "b", "c") + sep,
expected: 6,
},
{
root: filepath.Join("foo", "bar", "baz"),
path: filepath.Join("foo", "bar", "baz", "a", "b", "c"),
expected: 3,
},
{
root: filepath.Join("foo", "bar", "baz") + sep,
path: filepath.Join("foo", "bar", "baz", "a", "b", "c"),
expected: 3,
},
}
for i, testCase := range testCases {
if expected, actual := testCase.expected, depth(testCase.root, testCase.path); actual != expected {
t.Errorf("[testCase=%va] Expected depth=%v but result=%v for % #v", i, expected, actual, testCase)
}
testCase.root = sep + testCase.root
testCase.path = sep + testCase.path
if expected, actual := testCase.expected, depth(testCase.root, testCase.path); actual != expected {
t.Errorf("[testCase=%vb] Expected depth=%v but result=%v for % #v", i, expected, actual, testCase)
}
}
}