mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
Handle newlines between filename (#250)
This commit is contained in:
@@ -3,7 +3,7 @@ import re
|
||||
|
||||
def parse_chat(chat): # -> List[Tuple[str, str]]:
|
||||
# Get all ``` blocks and preceding filenames
|
||||
regex = r"(\S+?)\n```\S+\n(.+?)```"
|
||||
regex = r"(\S+)\n\s*```[^\n]*\n(.+?)```"
|
||||
matches = re.finditer(regex, chat, re.DOTALL)
|
||||
|
||||
files = []
|
||||
|
||||
@@ -144,3 +144,57 @@ def test_files_with_back_tick():
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
|
||||
def test_files_with_newline_between():
|
||||
chat = textwrap.dedent(
|
||||
"""
|
||||
This is a sample program.
|
||||
|
||||
file1.py
|
||||
|
||||
```python
|
||||
print("Hello, World!")
|
||||
```
|
||||
"""
|
||||
)
|
||||
|
||||
workspace = {}
|
||||
to_files(chat, workspace)
|
||||
|
||||
assert workspace["all_output.txt"] == chat
|
||||
|
||||
expected_files = {
|
||||
"file1.py": 'print("Hello, World!")\n',
|
||||
"README.md": "\nThis is a sample program.\n\nfile1.py\n\n",
|
||||
}
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
|
||||
def test_files_with_newline_between_header():
|
||||
chat = textwrap.dedent(
|
||||
"""
|
||||
This is a sample program.
|
||||
|
||||
## file1.py
|
||||
|
||||
```python
|
||||
print("Hello, World!")
|
||||
```
|
||||
"""
|
||||
)
|
||||
|
||||
workspace = {}
|
||||
to_files(chat, workspace)
|
||||
|
||||
assert workspace["all_output.txt"] == chat
|
||||
|
||||
expected_files = {
|
||||
"file1.py": 'print("Hello, World!")\n',
|
||||
"README.md": "\nThis is a sample program.\n\n## file1.py\n\n",
|
||||
}
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
Reference in New Issue
Block a user