-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparent_test.go
More file actions
88 lines (78 loc) · 2.7 KB
/
Copy pathparent_test.go
File metadata and controls
88 lines (78 loc) · 2.7 KB
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
package runpath
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// Test_parentNamespace_Path tests the PARENT.Path function returns parent DIR path
// Test_parentNamespace_Path 测试 PARENT.Path 函数返回父 DIR 路径
func Test_parentNamespace_Path(t *testing.T) {
path := PARENT.Path()
t.Log(path)
require.True(t, filepath.IsAbs(path))
require.Equal(t, "runpath", filepath.Base(path))
}
// Test_parentNamespace_Name tests the PARENT.Name function returns parent DIR name
// Test_parentNamespace_Name 测试 PARENT.Name 函数返回父 DIR 名称
func Test_parentNamespace_Name(t *testing.T) {
name := PARENT.Name()
t.Log(name)
require.Equal(t, "runpath", name)
}
// Test_parentNamespace_Skip tests the PARENT.Skip function with different skip depths
// Test_parentNamespace_Skip 测试 PARENT.Skip 函数使用不同的跳过深度
func Test_parentNamespace_Skip(t *testing.T) {
path := PARENT.Skip(0)
t.Log(path)
require.Equal(t, PARENT.Path(), path)
}
// Test_parentNamespace_Join tests the PARENT.Join function joins paths with parent DIR
// Test_parentNamespace_Join 测试 PARENT.Join 函数与父 DIR 连接路径
func Test_parentNamespace_Join(t *testing.T) {
path := PARENT.Join("example.json")
t.Log(path)
want := filepath.Join(PARENT.Path(), "example.json")
require.Equal(t, want, path)
}
// Test_parentNamespace_Join1 tests constructing paths using DIR.Path and filepath.Join
// Test_parentNamespace_Join1 测试使用 DIR.Path 和 filepath.Join 构建路径
func Test_parentNamespace_Join1(t *testing.T) {
name := Name()
t.Log(name)
root := DIR.Path() // Named "root" to match the package naming convention // 变量名为 "root" 保持代码美学
t.Log(root)
path := filepath.Join(root, name)
t.Log(path)
want := Path()
t.Log(want)
require.Equal(t, want, path)
}
// Test_parentNamespace_Join2 tests DIR.Join produces same result as filepath.Join
// Test_parentNamespace_Join2 测试 DIR.Join 与 filepath.Join 产生相同结果
func Test_parentNamespace_Join2(t *testing.T) {
name := Name()
t.Log(name)
path := DIR.Join(name)
t.Log(path)
want := Path()
t.Log(want)
require.Equal(t, want, path)
}
// Test_parentNamespace_Up tests DIR.Up navigates up DIR structure
// Test_parentNamespace_Up 测试 DIR.Up 向上导航 DIR 结构
func Test_parentNamespace_Up(t *testing.T) {
for depth := 0; depth < 10; depth++ {
t.Log(DIR.Up(depth))
}
}
// Test_parentNamespace_UpTo tests DIR.UpTo navigates up and joins paths
// Test_parentNamespace_UpTo 测试 DIR.UpTo 向上导航并连接路径
func Test_parentNamespace_UpTo(t *testing.T) {
name := DIR.Name()
t.Log(name)
path := DIR.UpTo(1, name)
t.Log(path)
want := DIR.Path()
t.Log(want)
require.Equal(t, want, path)
}