Skip to content

Commit

Permalink
Reformat markdown tests with dedent() (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Aug 16, 2023
1 parent 7cd5f30 commit 94465e8
Showing 1 changed file with 85 additions and 13 deletions.
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

0 comments on commit 94465e8

Please sign in to comment.