commit
0918b33472
3 changed files with 19 additions and 0 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue