mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
Fix square bracket file name issue
This commit is contained in:
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