Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat markdown tests with dedent() #270

Merged
merged 1 commit into from Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 85 additions & 13 deletions tests/test_blacken_docs.py
Expand Up @@ -18,40 +18,112 @@ def test_format_src_trivial():


def test_format_src_markdown_simple():
before = "```python\n" "f(1,2,3)\n" "```\n"
before = dedent(
"""\
```python
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == ("```python\n" "f(1, 2, 3)\n" "```\n")
assert after == dedent(
"""\
```python
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_leading_whitespace():
before = "``` python\n" "f(1,2,3)\n" "```\n"
before = dedent(
"""\
``` python
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == ("``` python\n" "f(1, 2, 3)\n" "```\n")
assert after == dedent(
"""\
``` python
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_short_name():
before = "``` py\n" "f(1,2,3)\n" "```\n"
before = dedent(
"""\
``` py
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == ("``` py\n" "f(1, 2, 3)\n" "```\n")
assert after == dedent(
"""\
``` py
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_options():
before = "```python title='example.py'\n" + "f(1,2,3)\n" + "```\n"
before = dedent(
"""\
```python title='example.py'
f(1,2,3)
```
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == ("```python title='example.py'\n" + "f(1, 2, 3)\n" + "```\n")
assert after == dedent(
"""\
```python title='example.py'
f(1, 2, 3)
```
"""
)


def test_format_src_markdown_trailing_whitespace():
before = "```python\n" "f(1,2,3)\n" "``` \n"
before = dedent(
"""\
```python
f(1,2,3)
``` \n"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == ("```python\n" "f(1, 2, 3)\n" "``` \n")
assert after == dedent(
"""\
```python
f(1, 2, 3)
``` \n"""
)


def test_format_src_indented_markdown():
before = "- do this pls:\n" " ```python\n" " f(1,2,3)\n" " ```\n" "- also this\n"
before = dedent(
"""\
- do this pls:
```python
f(1,2,3)
```
- also this
"""
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == (
"- do this pls:\n" " ```python\n" " f(1, 2, 3)\n" " ```\n" "- also this\n"
assert after == dedent(
"""\
- do this pls:
```python
f(1, 2, 3)
```
- also this
"""
)


Expand Down