package action import "testing" // TestVolumeMethodSelection 验证 method 参数归一化与校验: // 默认("")→ media;hotkey 为 media 别名;com 保留为精确选项。 func TestVolumeMethodSelection(t *testing.T) { cases := []struct { in string want string }{ {"", "media"}, {"media", "media"}, {"hotkey", "media"}, {"com", "com"}, {"bogus", "media"}, // Validate 拦截前的兜底 } for _, c := range cases { if got := volumeMethod(c.in); got != c.want { t.Errorf("volumeMethod(%q) = %q, want %q", c.in, got, c.want) } } for _, id := range []string{"volume_up", "volume_down", "toggle_mute"} { a, err := New(id) if err != nil { t.Fatalf("New(%q): %v", id, err) } for _, m := range []string{"", "media", "com", "hotkey"} { if err := a.Validate(map[string]any{"method": m}); err != nil { t.Errorf("%s method %q should pass: %v", id, m, err) } } if err := a.Validate(map[string]any{"method": "cli"}); err == nil { t.Errorf("%s invalid method should fail", id) } } } // TestVolumeStepCount 验证媒体键路径按键次数 = |delta|。 func TestVolumeStepCount(t *testing.T) { cases := []struct { delta int32 want int }{ {1, 1}, {3, 3}, {-1, 1}, {-5, 5}, {0, 0}, } for _, c := range cases { if got := volumeStepCount(c.delta); got != c.want { t.Errorf("volumeStepCount(%d) = %d, want %d", c.delta, got, c.want) } } } // TestVolumeSchemaDefaultMedia 回归:schema 默认值必须为 media(方案A的落点)。 func TestVolumeSchemaDefaultMedia(t *testing.T) { up, _ := New("volume_up") for _, p := range up.Schema().Params { if p.Name == "method" && p.Default != "media" { t.Errorf("volume_up method default = %v, want media", p.Default) } } mu, _ := New("toggle_mute") for _, p := range mu.Schema().Params { if p.Name == "method" && p.Default != "media" { t.Errorf("toggle_mute method default = %v, want media", p.Default) } } }