Skip to content

Commit

Permalink
Merge pull request #358 from trheyi/main
Browse files Browse the repository at this point in the history
[add] process utils.str.UUID
  • Loading branch information
trheyi authored Apr 9, 2023
2 parents b608578 + 2f77721 commit 0918b33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func init() {
process.Alias("xiang.helper.HexToString", "utils.str.Hex")
process.Register("utils.str.Join", str.ProcessJoin)
process.Register("utils.str.JoinPath", str.ProcessJoinPath)
process.Register("utils.str.UUID", str.ProcessUUID)

// Array
process.Alias("xiang.helper.ArrayPluck", "utils.arr.Pluck")
Expand Down
7 changes: 7 additions & 0 deletions utils/str/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"

"github.com/google/uuid"
"github.com/yaoapp/gou/process"
)

Expand All @@ -29,3 +30,9 @@ func ProcessJoinPath(process *process.Process) interface{} {
}
return filepath.Join(paths...)
}

// ProcessUUID utils.str.uuid
func ProcessUUID(process *process.Process) interface{} {
uuid := uuid.New()
return uuid.String()
}
11 changes: 11 additions & 0 deletions utils/str_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
_ "github.com/yaoapp/yao/helper"
Expand All @@ -21,6 +22,16 @@ func TestProcessStrJoinPath(t *testing.T) {
assert.Equal(t, shouldBe, res)
}

func TestProcessUUID(t *testing.T) {
res := process.New("utils.str.UUID").Run().(string)
_, err := uuid.Parse(res)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, 36, len(res))
}

func TestProcessStrHex(t *testing.T) {
res, err := process.New("utils.str.Hex", []byte{0x0, 0x1}).Exec()
assert.Nil(t, err)
Expand Down

0 comments on commit 0918b33

Please sign in to comment.