-
Notifications
You must be signed in to change notification settings - Fork 10
/
util_test.go
50 lines (43 loc) · 1.04 KB
/
util_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
//
// Copyright (c) 2018 Dean Jackson <[email protected]>
//
// MIT Licence. See http://opensource.org/licenses/MIT
//
// Created on 2018-01-26
//
package main
import "testing"
func TestRelDepth(t *testing.T) {
data := []struct {
base, dir string
depth int
}{
{"", "", 0},
{".", ".", 0},
{".", ".", 0},
{"/", "/", 0},
{"/", "/dir1", 1},
{"/", "/dir1/dir2", 2},
{"/", "/dir1/dir2/dir3", 3},
{"/", "/dir1/dir2/dir3/dir4", 4},
{"/dir1", "/dir1/dir2/dir3/dir4", 3},
{"/dir1/dir2", "/dir1/dir2/dir3/dir4", 2},
{"/dir1/dir2/dir3", "/dir1/dir2/dir3/dir4", 1},
{"", "dir1", 1},
{"", "dir1/dir2", 2},
{"", "dir1/dir2/dir3", 3},
{"", "dir1/dir2/dir3/dir4", 4},
{"dir1", "dir1/dir2/dir3/dir4", 3},
{"dir1/dir2", "dir1/dir2/dir3/dir4", 2},
{"dir1/dir2/dir3", "dir1/dir2/dir3/dir4", 1},
{"/dir1", "/dir2", -1},
{"/dir1", "/", -1},
}
for _, td := range data {
n := reldepth(td.base, td.dir)
if n != td.depth {
t.Errorf("Bad Depth. Expected=%d, Got=%d, Base=%s, Dir=%s",
td.depth, n, td.base, td.dir)
}
}
}