Skip to content

Commit

Permalink
增加简化函数
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyile committed Dec 1, 2024
1 parent 93f4358 commit 4d325b4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func TestSrcPathChangeExtension(t *testing.T) {
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/utils_runtestpath.json"))
}

func TestSrcRex(t *testing.T) {
path := SrcRex(t, ".json")
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/runtestpath.json"))
}
```

This allows you to load different types of files (e.g., configuration files) based on the **execution location** and test requirements.
Expand Down
6 changes: 6 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func TestSrcPathChangeExtension(t *testing.T) {
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/utils_runtestpath.json"))
}

func TestSrcRex(t *testing.T) {
path := SrcRex(t, ".json")
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/runtestpath.json"))
}
```

这样你就可以根据不同的测试需求加载不同格式的文件。
Expand Down
8 changes: 8 additions & 0 deletions runpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func GetPathChangeExtension(pointExtension string) string {
return GetSkipRemoveExtension(1) + pointExtension
}

func GetRex(pointExtension string) string {
return GetSkipRemoveExtension(1) + pointExtension
}

func GetNox() string {
return GetSkipRemoveExtension(1)
}

// GetPathRemoveExtension 把当前源码的文件路径去除结尾.go,这个函数好像使用的频率不会很高吧,当然也不是很确定呢,就这样留着吧
func GetPathRemoveExtension() string {
return GetSkipRemoveExtension(1)
Expand Down
12 changes: 12 additions & 0 deletions runpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ func TestGetPathChangeExtension(t *testing.T) {
require.True(t, strings.HasSuffix(path, "runpath/runpath_test.json"))
}

func TestGetRex(t *testing.T) {
path := GetRex(".json")
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runpath_test.json"))
}

func TestGetNox(t *testing.T) {
path := GetNox()
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runpath_test"))
}

func TestGetPathRemoveExtension(t *testing.T) {
path := GetPathRemoveExtension()
t.Log(path)
Expand Down
8 changes: 8 additions & 0 deletions runtestpath/runtestpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func SrcPathChangeExtension(t *testing.T, pointExtension string) string {
return SrcSkipRemoveExtension(t, 1) + pointExtension
}

func SrcRex(t *testing.T, pointExtension string) string {
return SrcSkipRemoveExtension(t, 1) + pointExtension
}

func SrcNox(t *testing.T) string {
return SrcSkipRemoveExtension(t, 1)
}

func SrcPathRemoveExtension(t *testing.T) string {
return SrcSkipRemoveExtension(t, 1)
}
Expand Down
12 changes: 12 additions & 0 deletions runtestpath/runtestpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ func TestSrcPathChangeExtension(t *testing.T) {
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/runtestpath.json"))
}

func TestSrcRex(t *testing.T) {
path := SrcRex(t, ".json")
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/runtestpath.json"))
}

func TestSrcNox(t *testing.T) {
path := SrcNox(t)
t.Log(path)
require.True(t, strings.HasSuffix(path, "runpath/runtestpath/runtestpath"))
}

func TestSrcPathRemoveExtension(t *testing.T) {
path := SrcPathRemoveExtension(t)
t.Log(path)
Expand Down

0 comments on commit 4d325b4

Please sign in to comment.