test: 补充单元测试覆盖率 29.9% → 36.6%
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

新建 18 个测试文件,追加 30 个已有测试文件,覆盖协议解析、
错误分类、CEL 表达式求值、YAML 反序列化、字节编码等纯函数。
This commit is contained in:
ZacharyZcR
2026-06-15 19:11:15 +08:00
parent d7dbccab76
commit 353d525642
48 changed files with 7556 additions and 1 deletions
+51
View File
@@ -1342,3 +1342,54 @@ func TestRandomStrRejectsNegativeLength(t *testing.T) {
t.Fatalf("RandomStr negative length = %q, want empty", got)
}
}
// =============================================================================
// MakeVarDecl 测试
// =============================================================================
func TestMakeVarDecl(t *testing.T) {
tests := []struct {
name string
key string
value string
wantIdent string // 期望 Decl.Name
wantKind string // "int" / "string" / "object"
}{
{"randomInt 前缀 -> Int", "myrand", "randomInt(1,100)", "myrand", "int"},
{"newReverse 前缀 -> Object", "myrev", "newReverse()", "myrev", "object"},
{"普通字符串 -> String", "myvar", "somevalue", "myvar", "string"},
{"空值 -> String", "empty", "", "empty", "string"},
{"randomIntExtra -> Int", "n", "randomInt(0, 65535)", "n", "int"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
decl := MakeVarDecl(tt.key, tt.value)
if decl == nil {
t.Fatal("MakeVarDecl() returned nil")
}
if decl.Name != tt.wantIdent {
t.Errorf("Decl.Name = %q, want %q", decl.Name, tt.wantIdent)
}
// 通过 Type 字段判断类型种类
tp := decl.GetIdent().GetType()
if tp == nil {
t.Fatal("Decl.GetIdent().GetType() == nil")
}
switch tt.wantKind {
case "int":
if tp.GetPrimitive().String() != "INT64" {
t.Errorf("type = %v, want INT64", tp)
}
case "string":
if tp.GetPrimitive().String() != "STRING" {
t.Errorf("type = %v, want STRING", tp)
}
case "object":
if tp.GetMessageType() == "" {
t.Errorf("type = %v, want MessageType", tp)
}
}
})
}
}