Skip to content

Commit c7eec0a

Browse files
committed
Fix /copy command (and add a unit test)
1 parent 0e217a1 commit c7eec0a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

aicodebot/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def copy(self, human_input):
108108
if not self.code_blocks:
109109
self.console.print("No code blocks to copy.", style=self.console.error_style)
110110
else:
111-
pyperclip.copy(self.code_blocks)
111+
pyperclip.copy("\n".join(self.code_blocks))
112112
self.console.print(Panel("✅ Copied code blocks to clipboard."))
113113
return self.CONTINUE
114114

tests/test_input.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from io import StringIO
55
from pathlib import Path
66
from tests.conftest import in_temp_directory
7-
import pytest, textwrap
7+
import pyperclip, pytest, textwrap
88

99

1010
class MockConsole:
@@ -88,3 +88,14 @@ def test_apply_subcommand(chat, temp_git_repo):
8888

8989
# Check if the file was properly modified
9090
assert "It is now even better!" in mod_file.read_text()
91+
92+
93+
def test_copy_subcommand(chat, temp_git_repo):
94+
with in_temp_directory(temp_git_repo.working_dir):
95+
# Add the patch to the chat (simulating it coming in from the LM response)
96+
chat.code_blocks = ["code block 1", "code block 2"]
97+
98+
# Apply the patch using the /apply command
99+
assert chat.parse_human_input("/copy") == chat.CONTINUE
100+
101+
assert pyperclip.paste() is "\n".join(chat.code_blocks)

0 commit comments

Comments
 (0)