forked from julianschill/klipper-led_effect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(preview_generator): Write tests for markdown regex
- Loading branch information
Showing
7 changed files
with
190 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 +1,2 @@ | ||
from .preview_generator import generate_preview | ||
from .preview_generator import generate_preview | ||
from .markdown_regex import markdown_regex |
3 changes: 3 additions & 0 deletions
3
packages/preview_generator/preview_generator/markdown_regex.py
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,3 @@ | ||
import re | ||
|
||
markdown_regex = re.compile(r'(\!\[Preview\]\(.+?\)\n\n)?(?P<block>```(layers|\nlayers\:)\n(?P<layers>.*?)\n```)', re.DOTALL) |
73 changes: 73 additions & 0 deletions
73
packages/preview_generator/preview_generator/markdown_regex_test.py
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,73 @@ | ||
import re | ||
from . import markdown_regex | ||
|
||
def test_with_one_lines(): | ||
text = """ | ||
Long text | ||
```layers | ||
static | ||
``` | ||
""" | ||
match = markdown_regex.search(text) | ||
assert match.groupdict() == { | ||
'block': '```layers\nstatic\n```', | ||
'layers': 'static' | ||
} | ||
|
||
def test_with_two_lines(): | ||
text = """ | ||
Long text | ||
```layers | ||
static | ||
breathing | ||
``` | ||
""" | ||
match = markdown_regex.search(text) | ||
assert match.groupdict() == { | ||
'block': '```layers\nstatic\nbreathing\n```', | ||
'layers': 'static\nbreathing' | ||
} | ||
|
||
def test_with_layers_on_extra_line_with_colon(): | ||
text = """ | ||
Long text | ||
``` | ||
layers: | ||
static | ||
breathing | ||
``` | ||
""" | ||
match = markdown_regex.search(text) | ||
assert match.groupdict() == { | ||
'block': '```\nlayers:\n static\n breathing\n```', | ||
'layers': ' static\n breathing' | ||
} | ||
|
||
|
||
def test_with_preceeding_preview_image(): | ||
text = """ | ||
Long text | ||
![Preview](./woop.png) | ||
``` | ||
layers: | ||
static | ||
breathing | ||
``` | ||
""" | ||
match = markdown_regex.search(text) | ||
assert match.group(0) == """![Preview](./woop.png) | ||
``` | ||
layers: | ||
static | ||
breathing | ||
```""" | ||
assert match.groupdict() == { | ||
'block': '```\nlayers:\n static\n breathing\n```', | ||
'layers': ' static\n breathing' | ||
} |
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