mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 20:55:09 +01:00
Fix square bracket file name issue
This commit is contained in:
@@ -11,6 +11,9 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:
|
|||||||
# Strip the filename of any non-allowed characters and convert / to \
|
# Strip the filename of any non-allowed characters and convert / to \
|
||||||
path = re.sub(r'[<>"|?*]', "", match.group(1))
|
path = re.sub(r'[<>"|?*]', "", match.group(1))
|
||||||
|
|
||||||
|
# Remove leading and trailing brackets
|
||||||
|
path = re.sub(r"^\[(.*)\]$", r"\1", path)
|
||||||
|
|
||||||
# Get the code
|
# Get the code
|
||||||
code = match.group(2)
|
code = match.group(2)
|
||||||
|
|
||||||
|
|||||||
94
tests/test_chat_to_files.py
Normal file
94
tests/test_chat_to_files.py
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import textwrap
|
||||||
|
|
||||||
|
from gpt_engineer.chat_to_files import to_files
|
||||||
|
|
||||||
|
|
||||||
|
def test_to_files():
|
||||||
|
chat = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
This is a sample program.
|
||||||
|
|
||||||
|
file1.py
|
||||||
|
```python
|
||||||
|
print("Hello, World!")
|
||||||
|
```
|
||||||
|
|
||||||
|
file2.py
|
||||||
|
```python
|
||||||
|
def add(a, b):
|
||||||
|
return a + b
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
workspace = {}
|
||||||
|
to_files(chat, workspace)
|
||||||
|
|
||||||
|
assert workspace["all_output.txt"] == chat
|
||||||
|
|
||||||
|
expected_files = {
|
||||||
|
"file1.py": 'print("Hello, World!")\n',
|
||||||
|
"file2.py": "def add(a, b):\n return a + b\n",
|
||||||
|
"README.md": "\nThis is a sample program.\n\nfile1.py\n",
|
||||||
|
}
|
||||||
|
|
||||||
|
for file_name, file_content in expected_files.items():
|
||||||
|
assert workspace[file_name] == file_content
|
||||||
|
|
||||||
|
|
||||||
|
def test_to_files_with_square_brackets():
|
||||||
|
chat = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
This is a sample program.
|
||||||
|
|
||||||
|
[file1.py]
|
||||||
|
```python
|
||||||
|
print("Hello, World!")
|
||||||
|
```
|
||||||
|
|
||||||
|
[file2.py]
|
||||||
|
```python
|
||||||
|
def add(a, b):
|
||||||
|
return a + b
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
workspace = {}
|
||||||
|
to_files(chat, workspace)
|
||||||
|
|
||||||
|
assert workspace["all_output.txt"] == chat
|
||||||
|
|
||||||
|
expected_files = {
|
||||||
|
"file1.py": 'print("Hello, World!")\n',
|
||||||
|
"file2.py": "def add(a, b):\n return a + b\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
|
||||||
|
|
||||||
|
|
||||||
|
def test_files_with_brackets_in_name():
|
||||||
|
chat = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
This is a sample program.
|
||||||
|
|
||||||
|
[id].jsx
|
||||||
|
```javascript
|
||||||
|
console.log("Hello, World!")
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
workspace = {}
|
||||||
|
to_files(chat, workspace)
|
||||||
|
|
||||||
|
assert workspace["all_output.txt"] == chat
|
||||||
|
|
||||||
|
expected_files = {
|
||||||
|
"[id].jsx": 'console.log("Hello, World!")\n',
|
||||||
|
"README.md": "\nThis is a sample program.\n\n[id].jsx\n",
|
||||||
|
}
|
||||||
|
|
||||||
|
for file_name, file_content in expected_files.items():
|
||||||
|
assert workspace[file_name] == file_content
|
||||||
Reference in New Issue
Block a user