[add] migrate helper & utils

This commit is contained in:
Max 2023-02-03 11:17:05 +08:00
parent 8b5563f697
commit f2b31c17db
5 changed files with 18 additions and 41 deletions

View file

@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}')
NOW := $(shell date +"%FT%T%z")
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime' | grep -vE 'examples|tests*|config|widgets')
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils' | grep -vE 'examples|tests*|config|widgets')
TESTTAGS ?= ""
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)

View file

@ -1,13 +1,10 @@
package helper
import (
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
"github.com/yaoapp/yao/share"
)
func TestProcessHexToString(t *testing.T) {
@ -23,39 +20,3 @@ func TestProcessHexToString(t *testing.T) {
assert.Nil(t, err)
assert.Nil(t, res)
}
func TestProcessHexToStringInFlow(t *testing.T) {
// testflow := path.Join(os.Getenv("YAO_DEV"), "tests", "flows", "helper")
// flow.Load(testflow, "helper.")
res, err := process.New("flows.helper.HexToString").Exec()
assert.Nil(t, err)
assert.Equal(t, "6162", res) // ab
}
func TestProcessHexToStringInScript(t *testing.T) {
testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts")
share.LoadFrom(testscirpt)
res, err := process.New("scripts.helper.HexToStringString").Exec()
assert.Nil(t, err)
assert.Equal(t, "6162", res) // ab
res, err = process.New("scripts.helper.HexToStringBytes", []byte{0x0, 0x1}).Exec()
assert.Nil(t, err)
assert.Equal(t, "0001", res) // []byte{0x0, 0x1}
}
func TestProcessBufferInScript(t *testing.T) {
testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts")
share.LoadFrom(testscirpt)
res, err := process.New("scripts.helper.Buffer").Exec()
assert.Nil(t, err)
str, ok := res.(string)
assert.True(t, ok)
assert.Equal(t, []byte{0x0, 0x1}, []byte(str))
}

View file

@ -27,7 +27,7 @@ func init() {
process.Register("xiang.helper.MapDel", ProcessMapDel) // deprecated → utils.map.Del @/utils/process.go
process.Register("xiang.helper.MapMultiDel", ProcessMapMultiDel) // deprecated → utils.map.DelMany @/utils/process.go
process.Register("xiang.helper.HexToString", ProcessHexToString) // deprecated
process.Register("xiang.helper.HexToString", ProcessHexToString) // deprecated → utils.str.Hex @/utils/process.go new 2022.2.3
process.Register("xiang.helper.StrConcat", ProcessStrConcat) // deprecated → utils.str.Concat @/utils/process.go

View file

@ -50,6 +50,7 @@ func init() {
// String
process.Alias("xiang.helper.StrConcat", "utils.str.Concat")
process.Alias("xiang.helper.HexToString", "utils.str.Hex")
process.Register("utils.str.Join", str.ProcessJoin)
process.Register("utils.str.JoinPath", str.ProcessJoinPath)

View file

@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
_ "github.com/yaoapp/yao/helper"
)
func TestProcessStrJoin(t *testing.T) {
@ -19,3 +20,17 @@ func TestProcessStrJoinPath(t *testing.T) {
shouldBe := fmt.Sprintf("data%s20%sapp", string(os.PathSeparator), string(os.PathSeparator))
assert.Equal(t, shouldBe, res)
}
func TestProcessStrHex(t *testing.T) {
res, err := process.New("utils.str.Hex", []byte{0x0, 0x1}).Exec()
assert.Nil(t, err)
assert.Equal(t, "0001", res)
res, err = process.New("utils.str.Hex", string([]byte{0x0, 0x1})).Exec()
assert.Nil(t, err)
assert.Equal(t, "0001", res)
res, err = process.New("utils.str.Hex", 1024).Exec()
assert.Nil(t, err)
assert.Nil(t, res)
}