feat: 重构顺运宝规格主链路 (#88)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package spec
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSpecKey_只折叠空白(t *testing.T) {
|
||||
got, err := SpecKey(" 黑色,\tM【建議40-50公斤】 \n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "黑色, M【建議40-50公斤】" {
|
||||
t.Fatalf("SpecKey=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpecKey_不依赖规格解析(t *testing.T) {
|
||||
got, err := SpecKey("紅色,3XL建議80-90公斤】")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "紅色,3XL建議80-90公斤】" {
|
||||
t.Fatalf("SpecKey=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpecKey_拒绝空值和超长值(t *testing.T) {
|
||||
if _, err := SpecKey(" \t\n "); err == nil {
|
||||
t.Fatal("空规格必须报错")
|
||||
}
|
||||
if _, err := SpecKey(strings.Repeat("规", MaxKeyRunes+1)); err == nil {
|
||||
t.Fatal("超长规格必须报错")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user