-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from gptme.codeblock import Codeblock | ||
|
||
|
||
def test_extract_codeblocks_basic(): | ||
markdown = """ | ||
Some text | ||
```python | ||
def hello(): | ||
print("Hello, World!") | ||
``` | ||
More text | ||
""" | ||
assert Codeblock.iter_from_markdown(markdown) == [ | ||
("python", 'def hello():\n print("Hello, World!")') | ||
] | ||
|
||
|
||
def test_extract_codeblocks_multiple(): | ||
markdown = """ | ||
```java | ||
public class Main { | ||
public static void main(String[] args) { | ||
System.out.println("Hello, Java!"); | ||
} | ||
} | ||
``` | ||
Some text | ||
```python | ||
def greet(name): | ||
return f"Hello, {name}!" | ||
``` | ||
""" | ||
assert Codeblock.iter_from_markdown(markdown) == [ | ||
( | ||
"java", | ||
'public class Main {\n public static void main(String[] args) {\n System.out.println("Hello, Java!");\n }\n}', | ||
), | ||
("python", 'def greet(name):\n return f"Hello, {name}!"'), | ||
] | ||
|
||
|
||
def test_extract_codeblocks_nested(): | ||
markdown = """ | ||
```python | ||
def print_readme(): | ||
print('''Usage: | ||
```javascript | ||
callme() | ||
``` | ||
''') | ||
``` | ||
""" | ||
assert Codeblock.iter_from_markdown(markdown) == [ | ||
( | ||
"python", | ||
"def print_readme():\n print('''Usage:\n```javascript\ncallme()\n```\n''')", | ||
) | ||
] | ||
|
||
|
||
def test_extract_codeblocks_empty(): | ||
assert Codeblock.iter_from_markdown("") == [] | ||
|
||
|
||
def test_extract_codeblocks_text_only(): | ||
assert ( | ||
Codeblock.iter_from_markdown("Just some regular text\nwithout any code blocks.") | ||
== [] | ||
) | ||
|
||
|
||
def test_extract_codeblocks_no_language(): | ||
markdown = """ | ||
``` | ||
def hello(): | ||
print("Hello, World!") | ||
``` | ||
""" | ||
assert Codeblock.iter_from_markdown(markdown) == [ | ||
("", 'def hello():\n print("Hello, World!")') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters