Additional filename handling (#221)

This commit is contained in:
David Cameron
2023-06-20 06:09:28 -04:00
committed by GitHub
parent dc834e6ad2
commit 9b3db78b95
2 changed files with 58 additions and 0 deletions

View File

@@ -14,6 +14,12 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:
# Remove leading and trailing brackets # Remove leading and trailing brackets
path = re.sub(r"^\[(.*)\]$", r"\1", path) 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 # Get the code
code = match.group(2) code = match.group(2)

View File

@@ -92,3 +92,55 @@ def test_files_with_brackets_in_name():
for file_name, file_content in expected_files.items(): for file_name, file_content in expected_files.items():
assert workspace[file_name] == file_content 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