package home import "testing" func TestNormalizeToolOK(t *testing.T) { b := "热" tone := "hot" got, err := normalizeTool(ReplaceInput{ RowIndex: 1, SortOrder: 1, Path: "/portrait", Icon: "portrait", Label: "愈心解码", Badge: &b, BadgeTone: &tone, Enabled: true, }) if err != nil || got.Label != "愈心解码" { t.Fatalf("got=%+v err=%v", got, err) } } func TestNormalizeToolRejects(t *testing.T) { cases := []ReplaceInput{ {RowIndex: 3, Path: "/a", Icon: "ask", Label: "x"}, {RowIndex: 1, Path: "https://evil.com", Icon: "ask", Label: "x"}, {RowIndex: 1, Path: "/../etc", Icon: "ask", Label: "x"}, {RowIndex: 1, Path: "/ask", Icon: "nope", Label: "x"}, {RowIndex: 1, Path: "/ask", Icon: "ask", Label: ""}, } for i, c := range cases { if _, err := normalizeTool(c); err != ErrInvalidTools { t.Fatalf("case %d want ErrInvalidTools got %v", i, err) } } }