package services import "testing" func TestParseMenuRights(t *testing.T) { cases := []struct { name string raw string want []uint64 }{ {"数字数组", "[15,36,37,263]", []uint64{15, 36, 37, 263}}, {"单元素数组", "[7]", []uint64{7}}, {"字符串数组", `["15","36"]`, []uint64{15, 36}}, {"逗号分隔", "15, 36 ,263", []uint64{15, 36, 263}}, {"空数组", "[]", nil}, {"空串", "", nil}, {"脏数据", "abc", nil}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got := ParseMenuRights(c.raw) if len(got) != len(c.want) { t.Fatalf("rights=%q 期望解析出 %d 个菜单 ID,实际 %d 个:%v", c.raw, len(c.want), len(got), got) } for _, id := range c.want { if !got[id] { t.Fatalf("rights=%q 期望包含菜单 ID %d,实际结果 %v", c.raw, id, got) } } }) } } func TestParseMenuRightsKeepsBoundaryIDs(t *testing.T) { got := ParseMenuRights("[15,36,37,38,263]") for _, id := range []uint64{15, 263} { if !got[id] { t.Fatalf("首尾菜单 ID %d 丢失,解析结果 %v", id, got) } } }