Files
fscan/webscan/lib/eval_misc_test.go
ZacharyZcR 0612255893 test: 补充单元测试覆盖率 29.9% → 36.6%
新建 18 个测试文件,追加 30 个已有测试文件,覆盖协议解析、
错误分类、CEL 表达式求值、YAML 反序列化、字节编码等纯函数。
2026-06-17 12:51:41 +08:00

54 lines
1009 B
Go

package lib
import (
"testing"
"unicode"
"github.com/google/cel-go/common/types"
)
func TestRegisterMiscImplementations_TongdaDate(t *testing.T) {
overloads := registerMiscImplementations()
idx := make(map[string]int, len(overloads))
for i, o := range overloads {
idx[o.Operator] = i
}
i, ok := idx["tongda_date"]
if !ok {
t.Fatal("overload tongda_date not found")
}
fn := overloads[i].Function
if fn == nil {
t.Fatal("tongda_date Function field is nil")
}
result := fn()
if types.IsError(result) {
t.Fatalf("unexpected error: %v", result)
}
got, ok := result.(types.String)
if !ok {
t.Fatalf("expected types.String, got %T", result)
}
s := string(got)
t.Run("length_is_4", func(t *testing.T) {
if len(s) != 4 {
t.Errorf("tongda_date returned %q, want 4-char string", s)
}
})
t.Run("all_digits", func(t *testing.T) {
for _, r := range s {
if !unicode.IsDigit(r) {
t.Errorf("tongda_date returned %q, contains non-digit char %q", s, r)
}
}
})
}