加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encode_test.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-05-30 08:43 . v0.1.1 统一单元测试格式
package dongle
import (
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncode_String(t *testing.T) {
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"hello world", "hello world"},
}
for index, test := range tests {
e := newEncode()
e.dst = []byte(test.input)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, fmt.Sprintf("%s", e), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncode_ToString(t *testing.T) {
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"hello world", "hello world"},
}
for index, test := range tests {
e := newEncode()
e.dst = []byte(test.input)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToString(), "Current test index is "+strconv.Itoa(index))
}
}
func TestEncode_ToBytes(t *testing.T) {
tests := []struct {
input string // 输入值
expected []byte // 期望值
}{
{"", []byte("")},
{"hello world", []byte("hello world")},
}
for index, test := range tests {
e := newEncode()
e.dst = []byte(test.input)
assert.Nil(t, e.Error)
assert.Equal(t, test.expected, e.ToBytes(), "Current test index is "+strconv.Itoa(index))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化