Merge pull request #358 from trheyi/main

[add] process utils.str.UUID
This commit is contained in:
Max 2023-04-09 20:05:59 +08:00 committed by GitHub
commit 0918b33472
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View file

@ -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")

View file

@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"
"github.com/google/uuid"
"github.com/yaoapp/gou/process"
)
@ -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()
}

View file

@ -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"
@ -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)