mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
Additional filename handling (#221)
This commit is contained in:
@@ -14,6 +14,12 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:
|
||||
# Remove leading and trailing brackets
|
||||
path = re.sub(r"^\[(.*)\]$", r"\1", path)
|
||||
|
||||
# Remove leading and trailing backticks
|
||||
path = re.sub(r"^`(.*)`$", r"\1", path)
|
||||
|
||||
# Remove trailing ]
|
||||
path = re.sub(r"\]$", "", path)
|
||||
|
||||
# Get the code
|
||||
code = match.group(2)
|
||||
|
||||
|
||||
@@ -92,3 +92,55 @@ def test_files_with_brackets_in_name():
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
|
||||
def test_files_with_file_colon():
|
||||
chat = textwrap.dedent(
|
||||
"""
|
||||
This is a sample program.
|
||||
|
||||
[FILE: 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[FILE: file1.py]\n",
|
||||
}
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
|
||||
def test_files_with_back_tick():
|
||||
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",
|
||||
}
|
||||
|
||||
for file_name, file_content in expected_files.items():
|
||||
assert workspace[file_name] == file_content
|
||||
|
||||
Reference in New Issue
Block a user