forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex_test.go
61 lines (47 loc) · 1.6 KB
/
hex_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package helper
import (
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou"
"github.com/yaoapp/yao/flow"
"github.com/yaoapp/yao/share"
)
func TestProcessHexToString(t *testing.T) {
res, err := gou.NewProcess("xiang.helper.HexToString", []byte{0x0, 0x1}).Exec()
assert.Nil(t, err)
assert.Equal(t, "0001", res)
res, err = gou.NewProcess("xiang.helper.HexToString", string([]byte{0x0, 0x1})).Exec()
assert.Nil(t, err)
assert.Equal(t, "0001", res)
res, err = gou.NewProcess("xiang.helper.HexToString", 1024).Exec()
assert.Nil(t, err)
assert.Nil(t, res)
}
func TestProcessHexToStringInFlow(t *testing.T) {
testflow := path.Join(os.Getenv("YAO_DEV"), "tests", "flows", "helper")
flow.LoadFrom(testflow, "helper.")
res, err := gou.NewProcess("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 := gou.NewProcess("scripts.helper.HexToStringString").Exec()
assert.Nil(t, err)
assert.Equal(t, "6162", res) // ab
res, err = gou.NewProcess("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 := gou.NewProcess("scripts.helper.Buffer").Exec()
assert.Nil(t, err)
str, ok := res.(string)
assert.True(t, ok)
assert.Equal(t, []byte{0x0, 0x1}, []byte(str))
}