git-subtree-dir: server git-subtree-mainline:c4e617ada7git-subtree-split:e64421295f
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package agent
|
|
|
|
import "testing"
|
|
|
|
func TestParsePlanOutput_Valid(t *testing.T) {
|
|
raw := `{"plans":[{"title":"通勤清爽","hairstyle":"清爽短发","hair_color":"#2B2B2B","items":[{"slot":"上衣","item_id":1,"name":"白衬衫","desc":"正式","new_item":false},{"slot":"鞋","item_id":3,"name":"小白鞋","desc":"百搭","new_item":false}]}]}`
|
|
out, err := ParsePlanOutput(raw)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(out.Plans) != 1 || out.Plans[0].Title != "通勤清爽" {
|
|
t.Fatalf("wrong parse result: %+v", out.Plans)
|
|
}
|
|
}
|
|
|
|
func TestParsePlanOutput_CodeFence(t *testing.T) {
|
|
raw := "```json\n{\"plans\":[{\"title\":\"周末约会\",\"hairstyle\":\"波浪卷发\",\"hair_color\":\"#8B4513\",\"items\":[{\"slot\":\"下装\",\"item_id\":0,\"name\":\"A字裙\",\"desc\":\"飘逸\",\"new_item\":true}]}]}\n```"
|
|
out, err := ParsePlanOutput(raw)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(out.Plans) != 1 || !out.Plans[0].Items[0].NewItem {
|
|
t.Fatalf("wrong parse result: %+v", out.Plans)
|
|
}
|
|
}
|
|
|
|
func TestParsePlanOutput_MissingPlans(t *testing.T) {
|
|
if _, err := ParsePlanOutput(`{"plans":[]}`); err == nil {
|
|
t.Fatal("expected error for empty plans")
|
|
}
|
|
}
|
|
|
|
func TestParsePlanOutput_InvalidJSON(t *testing.T) {
|
|
if _, err := ParsePlanOutput(`not json`); err == nil {
|
|
t.Fatal("expected error for invalid json")
|
|
}
|
|
}
|
|
|
|
func TestParsePlanOutput_InvalidSlot(t *testing.T) {
|
|
raw := `{"plans":[{"title":"x","hairstyle":"y","hair_color":"#fff","items":[{"slot":"帽子","item_id":1,"name":"a","desc":"b","new_item":false}]}]}`
|
|
if _, err := ParsePlanOutput(raw); err == nil {
|
|
t.Fatal("expected error for invalid slot")
|
|
}
|
|
}
|