Files
cmautobuy/admin/spec/shopee_spec_test.go
T

28 lines
1.1 KiB
Go

package spec
import "testing"
func TestParseShopeeSpec(t *testing.T) {
tests := []struct {
name, raw, color, size, advice string
ok bool
}{
{"基础格式", "黑色,M", "黑色", "M", "", true},
{"全角逗号", "白色,L【建議50-60公斤】", "白色", "L", "50-60公斤", true},
{"复合颜色描述", "黑色+白色【純棉兩件裝】 簡約親膚,L【建議52.5-60公斤】", "黑色+白色【純棉兩件裝】 簡約親膚", "L", "52.5-60公斤", true},
{"数字尺码前缀", "蓝色,2xl", "蓝色", "2XL", "", true},
{"额外维度", "黑色,M,两件", "", "", "", false},
{"未知尺码", "黑色,中码", "", "", "", false},
{"空建议", "黑色,M【】", "", "", "", false},
{"缺少颜色", ",M", "", "", "", false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, ok := ParseShopeeSpec(test.raw)
if ok != test.ok || got.Color != test.color || got.Size != test.size || got.Advice != test.advice {
t.Fatalf("ParseShopeeSpec(%q)=(%+v,%v),期望 (%q,%q,%q,%v)", test.raw, got, ok, test.color, test.size, test.advice, test.ok)
}
})
}
}