Skip to content

Commit

Permalink
test: expand unit tests based on mdformat-admon
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Mar 8, 2024
1 parent 3984fc6 commit fa959e4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[cov-link]: https://codecov.io/gh/executablebooks/mdformat-gfm-alerts
-->

An [mdformat](https://github.com/executablebooks/mdformat) plugin for [GitHub "Alerts"](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts) (and [community discussion](https://github.com/orgs/community/discussions/16925)).
An [mdformat](https://github.com/executablebooks/mdformat) plugin for [GitHub "Alerts"](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts). "Alerts" are a block quote variation of admonitions that were proposed in this [community discussion](https://github.com/orgs/community/discussions/16925) and are currently a separate extension of the [GFM (GitHub-Flavored Markdown) syntax](https://github.github.com/gfm).

## `mdformat` Usage

Expand Down
24 changes: 0 additions & 24 deletions tests/fixtures.md

This file was deleted.

Empty file added tests/format/__init__.py
Empty file.
47 changes: 47 additions & 0 deletions tests/format/fixtures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
2023 Syntax
.
> [!NOTE]
> Useful information that users should know, even when skimming content.
> [!TIP]
> Helpful advice for doing things better or more easily.
> [!IMPORTANT]
> Key information users need to know to achieve their goal.
> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.
> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.
.
> [!NOTE]
> Useful information that users should know, even when skimming content.
> [!TIP]
> Helpful advice for doing things better or more easily.
> [!IMPORTANT]
> Key information users need to know to achieve their goal.
> [!WARNING]
> Urgent info that needs immediate user attention to avoid problems.
> [!CAUTION]
> Advises about risks or negative outcomes of certain actions.
.

2022 (to 2023) Syntax
.
> **Note**
> This is a note
> **Warning**
> This is a warning
.
> [!NOTE]
> This is a note
> [!WARNING]
> This is a warning
.
14 changes: 9 additions & 5 deletions tests/test_fixtures.py → tests/format/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from pathlib import Path

from markdown_it.utils import read_fixture_file
import mdformat
import pytest
from markdown_it.utils import read_fixture_file

from ..helpers import print_text

FIXTURE_PATH = Path(__file__).parent / "fixtures.md"
fixtures = read_fixture_file(FIXTURE_PATH)


@pytest.mark.parametrize(
"line,title,text,expected", fixtures, ids=[f[1] for f in fixtures]
("line", "title", "text", "expected"),
fixtures,
ids=[f[1] for f in fixtures],
)
def test_fixtures(line, title, text, expected):
output = mdformat.text(text, extensions={"plugin"})
print(output)
assert output.rstrip() == expected.rstrip(), output
output = mdformat.text(text, extensions={"gfm_alerts"})
print_text(output, expected)
assert output.rstrip() == expected.rstrip()
Empty file added tests/render/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions tests/test_mdformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path

import mdformat


def test_mdformat_text():
"""Verify that using mdformat works as expected."""
content = (Path(__file__).parent / "pre-commit-test.md").read_text()

result = mdformat.text(
content,
options={"end-of-line": "keep"},
extensions={
"gfm_alerts",
},
)

assert result == content

0 comments on commit fa959e4

Please sign in to comment.