Files
bl/common/serialize/sturc/parse_test.go
昔念 cc9f1fb45a refactor(info): 删除多余的信息结构体文件
- 移除了多个未使用的 Java 和 Go 信息结构体文件
- 优化了项目结构,减少了冗余代码
- 这些文件可能是早期开发阶段的遗留代码,现在已不再需要
2025-06-23 10:15:22 +08:00

63 lines
1.1 KiB
Go

package struc
import (
"bytes"
"reflect"
"testing"
)
func parseTest(data interface{}) error {
_, err := parseFields(reflect.ValueOf(data))
return err
}
type empty struct{}
func TestEmptyStruc(t *testing.T) {
if err := parseTest(&empty{}); err == nil {
t.Fatal("failed to error on empty struct")
}
}
type chanStruct struct {
Test chan int
}
func TestChanError(t *testing.T) {
if err := parseTest(&chanStruct{}); err == nil {
// TODO: should probably ignore channel fields
t.Fatal("failed to error on struct containing channel")
}
}
type badSizeof struct {
Size int `struc:"sizeof=Bad"`
}
func TestBadSizeof(t *testing.T) {
if err := parseTest(&badSizeof{}); err == nil {
t.Fatal("failed to error on missing Sizeof target")
}
}
type missingSize struct {
Test []byte
}
func TestMissingSize(t *testing.T) {
if err := parseTest(&missingSize{}); err == nil {
t.Fatal("failed to error on missing field size")
}
}
type badNested struct {
Empty empty
}
func TestNestedParseError(t *testing.T) {
var buf bytes.Buffer
if err := Pack(&buf, &badNested{}); err == nil {
t.Fatal("failed to error on bad nested struct")
}
}