Skip to content

Commit 2c07b02

Browse files
committed
refactor(test): dissolve coverage_test.go into domain-specific test files
coverage_test.go was a catch-all that revealed a meta-goal ("coverage") rather than the domain it tests. Distribute all 91 tests into files named after what they test: - keymap_test.go (new): KeyBindingMap getter methods - keystroke_test.go (new): KeyStrokeKind.String, constructors, validate - platform_test.go (new): DetectTerminal, GetTerminalCapabilities, GetPlatformSpecificKeyBindings, GetTerminalSpecificKeyBindings - context_manager_test.go: SetContext, ForceEnvironment, Animator tests - profile_test.go: GetAllProfiles/Contexts, IsValid, Clone, Validate, GetProfileStatistics, CompareProfiles - runtime_profile_switch_test.go: ProfileSwitcher, HandleProfileSwitchCommand - features_test.go: ToYAML (simple + extended), formatKeystrokeForExport, Ke Ke Ke Ke Ke rseUserBindingValue
1 parent ccd7d77 commit 2c07b02

File tree

9 files changed

+1012
-1010
lines changed

9 files changed

+1012
-1010
lines changed

internal/keybindings/context_manager_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keybindings
22

33
import (
44
"testing"
5+
"time"
56

67
"github.com/bmf-san/ggc/v8/internal/config"
78
)
@@ -60,3 +61,100 @@ func TestContextManagerStackAndCallbacks(t *testing.T) {
6061
t.Fatalf("exit on empty stack returned %v", got)
6162
}
6263
}
64+
65+
// ── ContextManager: SetContext, ForceEnvironment ─────────────────────────────
66+
67+
func TestContextManager_SetContext(t *testing.T) {
68+
resolver := NewKeyBindingResolver(&config.Config{})
69+
RegisterBuiltinProfiles(resolver)
70+
cm := NewContextManager(resolver)
71+
72+
var transitions [][2]Context
73+
cm.RegisterContextCallback(ContextResults, func(from, to Context) {
74+
transitions = append(transitions, [2]Context{from, to})
75+
})
76+
77+
// SetContext to new context
78+
cm.SetContext(ContextResults)
79+
if cm.GetCurrentContext() != ContextResults {
80+
t.Errorf("SetContext: current = %v, want %v", cm.GetCurrentContext(), ContextResults)
81+
}
82+
if len(transitions) != 1 {
83+
t.Errorf("expected 1 transition callback, got %d", len(transitions))
84+
}
85+
86+
// SetContext to same context should be no-op
87+
cm.SetContext(ContextResults)
88+
if len(transitions) != 1 {
89+
t.Errorf("SetContext same context should not fire callback, got %d transitions", len(transitions))
90+
}
91+
92+
// Stack should be unmodified
93+
if len(cm.GetContextStack()) != 0 {
94+
t.Errorf("SetContext should not modify stack, got %v", cm.GetContextStack())
95+
}
96+
}
97+
98+
func TestContextManager_ForceEnvironment(t *testing.T) {
99+
resolver := NewKeyBindingResolver(&config.Config{})
100+
RegisterBuiltinProfiles(resolver)
101+
cm := NewContextManager(resolver)
102+
103+
// Should not panic
104+
cm.ForceEnvironment("darwin", "xterm-256color")
105+
}
106+
107+
func TestContextManager_ForceEnvironment_NilCM(t *testing.T) {
108+
var cm *ContextManager
109+
// Should not panic
110+
cm.ForceEnvironment("linux", "xterm")
111+
}
112+
113+
// ── ContextTransitionAnimator ────────────────────────────────────────────────
114+
115+
func TestContextTransitionAnimator_FadeAndSlide(t *testing.T) {
116+
cta := NewContextTransitionAnimator()
117+
cta.SetDuration(0) // no sleep in tests
118+
119+
cta.SetStyle("fade")
120+
cta.AnimateTransition(ContextGlobal, ContextResults)
121+
122+
cta.SetStyle("slide")
123+
cta.AnimateTransition(ContextGlobal, ContextInput)
124+
}
125+
126+
func TestContextTransitionAnimator_Disable(t *testing.T) {
127+
cta := NewContextTransitionAnimator()
128+
cta.Disable()
129+
// Should return early without doing anything
130+
cta.AnimateTransition(ContextGlobal, ContextResults)
131+
if cta.enabled {
132+
t.Error("expected disabled animator")
133+
}
134+
}
135+
136+
func TestContextTransitionAnimator_Enable(t *testing.T) {
137+
cta := NewContextTransitionAnimator()
138+
cta.Disable()
139+
cta.Enable()
140+
if !cta.enabled {
141+
t.Error("expected enabled animator")
142+
}
143+
}
144+
145+
func TestContextTransitionAnimator_RegisterAnimation(t *testing.T) {
146+
cta := NewContextTransitionAnimator()
147+
cta.RegisterAnimation(func(from, to Context) {})
148+
cta.RegisterAnimation(func(from, to Context) {})
149+
if len(cta.animations) != 2 {
150+
t.Errorf("expected 2 registered animations, got %d", len(cta.animations))
151+
}
152+
}
153+
154+
func TestContextTransitionAnimator_SetDuration(t *testing.T) {
155+
cta := NewContextTransitionAnimator()
156+
cta.SetDuration(500 * time.Millisecond)
157+
if cta.duration != 500*time.Millisecond {
158+
t.Errorf("duration = %v, want 500ms", cta.duration)
159+
}
160+
}

0 commit comments

Comments
 (0)