generated from executablebooks/mdformat-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
24 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
"""Test Helpers.""" | ||
|
||
from __future__ import annotations | ||
|
||
import re | ||
|
||
_SHOW_TEXT = True # PLANNED: Make configurable based on pytest CLI | ||
|
||
|
||
def _print(content: str, show_whitespace: bool) -> None: | ||
if show_whitespace: | ||
raise NotImplementedError("To use, port logic from `mdformat_mkdocs`") | ||
def separate_indent(line: str) -> tuple[str, str]: | ||
"""Separate leading indent from content. Also used by the test suite.""" | ||
re_indent = re.compile(r"(?P<indent>\s*)(?P<content>[^\s]?.*)") | ||
match = re_indent.match(line) | ||
assert match is not None # for pyright | ||
return (match["indent"], match["content"]) | ||
|
||
|
||
def _print(content: str, show_whitespace: bool) -> None: | ||
for line in content.split("\n"): | ||
print(line) | ||
indent, content = separate_indent(line) | ||
visible_indents = indent.replace(" ", "→").replace("\t", "➤") | ||
print((visible_indents if show_whitespace else indent) + content) | ||
|
||
|
||
def print_text(output: str, expected: str, show_whitespace: bool = False) -> None: | ||
"""Conditionall print text for debugging.""" | ||
if _SHOW_TEXT: | ||
print("-- Output --") | ||
_print(output.strip(), show_whitespace) | ||
_print(output, show_whitespace) | ||
print("-- Expected --") | ||
_print(expected.strip(), show_whitespace) | ||
_print(expected, show_whitespace) | ||
print("-- <End> --") |
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