diff options
Diffstat (limited to 'internal/tmuxedit/claude_agent_test.go')
| -rw-r--r-- | internal/tmuxedit/claude_agent_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/tmuxedit/claude_agent_test.go b/internal/tmuxedit/claude_agent_test.go index 1a80433..d8a68d9 100644 --- a/internal/tmuxedit/claude_agent_test.go +++ b/internal/tmuxedit/claude_agent_test.go @@ -103,6 +103,69 @@ func TestClaudeAgent_ClearInput(t *testing.T) { } } +func TestClaudeAgent_ExtractPrompt_EmptyPattern(t *testing.T) { + agent := &claudeAgent{baseAgent{promptPat: "", sectionPat: `^─{5,}`}} + got := agent.ExtractPrompt("──────\n❯ hello\n──────") + if got != "" { + t.Errorf("expected empty for empty pattern, got %q", got) + } +} + +func TestClaudeAgent_ExtractPrompt_InvalidRegex(t *testing.T) { + agent := &claudeAgent{baseAgent{promptPat: "[invalid", sectionPat: `^─{5,}`}} + got := agent.ExtractPrompt("──────\n❯ hello\n──────") + if got != "" { + t.Errorf("expected empty for invalid regex, got %q", got) + } +} + +func TestClaudeAgent_ExtractPrompt_ContinuationBreaksOnEmpty(t *testing.T) { + agent := newClaudeAgent() + // Empty line between prompt blocks should break continuation + content := "──────────────\n" + + "❯ first line\n" + + " continued\n" + + "\n" + + "unrelated text\n" + + "──────────────" + got := agent.ExtractPrompt(content) + want := "first line\ncontinued" + if got != want { + t.Errorf("ExtractPrompt() = %q, want %q", got, want) + } +} + +func TestClaudeAgent_ClearInput_Disabled(t *testing.T) { + agent := &claudeAgent{baseAgent{clearFirst: false, clearKeys: "C-a C-k"}} + err := agent.ClearInput("%1") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } +} + +func TestClaudeAgent_ClearInput_EmptyKeys(t *testing.T) { + agent := &claudeAgent{baseAgent{clearFirst: true, clearKeys: ""}} + err := agent.ClearInput("%1") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } +} + +func TestClaudeAgent_ClearInput_Error(t *testing.T) { + noSleep(t) + oldSend := sendKeys + defer func() { sendKeys = oldSend }() + sendKeys = func(string, ...string) error { + return fmt.Errorf("send failed") + } + + agent := newClaudeAgent() + err := agent.ClearInput("%1") + if err == nil { + t.Fatal("expected error from sendClearSequence failure") + } +} + func TestClaudeAgent_Detect(t *testing.T) { agent := newClaudeAgent() tests := []struct { |
