internal/providers/substyle/substyle_test.go
78 lines · 2132 bytes
5 symbols in this file
1package substyle_test
2
3import (
4 "testing"
5
6 "github.com/wraient/curd/internal/curdhost"
7 "github.com/wraient/curd/internal/providers/substyle"
8)
9
10func TestChooseHardPromptsForSoftFallback(t *testing.T) {
11 substyle.ResetForTest()
12 prompts := 0
13 previousPrompt := curdhost.PromptSelect
14 curdhost.Out = func(string) {}
15 curdhost.PromptSelect = func(options []curdhost.PromptOption) (curdhost.PromptOption, error) {
16 prompts++
17 return curdhost.PromptOption{Key: "soft", Label: options[0].Label}, nil
18 }
19 t.Cleanup(func() {
20 curdhost.PromptSelect = previousPrompt
21 substyle.ResetForTest()
22 })
23
24 style, err := substyle.Choose(true, false, "hard")
25 if err != nil || style != "soft" {
26 t.Fatalf("expected soft after prompt, got style=%q err=%v", style, err)
27 }
28 if prompts != 1 {
29 t.Fatalf("expected 1 prompt, got %d", prompts)
30 }
31}
32
33func TestChooseHardDeclinedSoftFallback(t *testing.T) {
34 substyle.ResetForTest()
35 previousPrompt := curdhost.PromptSelect
36 curdhost.PromptSelect = func([]curdhost.PromptOption) (curdhost.PromptOption, error) {
37 return curdhost.PromptOption{Key: "cancel", Label: "Cancel"}, nil
38 }
39 t.Cleanup(func() {
40 curdhost.PromptSelect = previousPrompt
41 substyle.ResetForTest()
42 })
43
44 _, err := substyle.Choose(true, false, "hard")
45 if err == nil {
46 t.Fatal("expected error when soft fallback is declined")
47 }
48}
49
50func TestChooseSoftFallsBackToHard(t *testing.T) {
51 style, err := substyle.Choose(false, true, "soft")
52 if err != nil || style != "hard" {
53 t.Fatalf("expected hard fallback, got style=%q err=%v", style, err)
54 }
55}
56
57func TestChooseAskAutoUsesSoftOnly(t *testing.T) {
58 substyle.ResetForTest()
59 messages := 0
60 previousOut := curdhost.Out
61 curdhost.Out = func(string) { messages++ }
62 t.Cleanup(func() {
63 curdhost.Out = previousOut
64 substyle.ResetForTest()
65 })
66
67 style, err := substyle.Choose(true, false, "ask")
68 if err != nil || style != "soft" {
69 t.Fatalf("expected soft, got style=%q err=%v", style, err)
70 }
71 if messages != 1 {
72 t.Fatalf("expected status message, got %d", messages)
73 }
74}
75
76func TestChooseAskDeclinedSoftOnly(t *testing.T) {
77 t.Skip("ask mode auto-accepts soft-only streams")
78}