26 lines
1.3 KiB
Python
26 lines
1.3 KiB
Python
import pytest
|
|
from mdhelper.markdown_utils import extract_headings_from_text, heading_locations
|
|
from mdhelper.markdown_renderer import MarkdownRenderer
|
|
from mdhelper.markdown_editor import MarkdownEditorDialog
|
|
|
|
|
|
@pytest.mark.parametrize('source,expected', [
|
|
('````markdown\n```\n# Fake\n````\n\n# Real',[('real',5)]),
|
|
('Title\n====\n\nBody',[('title',0)]),
|
|
('> # Quoted\n\n1. ### Listed',[('quoted',0),('listed',2)]),
|
|
(' # Fake\n\n# Real',[('real',2)]),
|
|
('# Same\n\nSame\n----\n\n> # Same',[('same',0),('same-2',2),('same-3',5)]),
|
|
('$$\n# Fake\n$$\n\n# Real',[('real',4)]),
|
|
])
|
|
def test_outline_reader_and_editor_use_identical_headings(qt_application,tmp_path,source,expected):
|
|
renderer=MarkdownRenderer(tmp_path);env={};renderer.markdown.parse(source,env)
|
|
assert [h.slug for h in extract_headings_from_text(source)]==[h['slug'] for h in env['headings']]
|
|
assert [(h.slug,line) for h,line in heading_locations(source)]==expected
|
|
editor=MarkdownEditorDialog(tmp_path/'note.md',source,renderer,'light',1,'',16)
|
|
try:
|
|
for slug,line in expected:
|
|
assert editor.scroll_to_heading(slug)
|
|
assert editor.editor.textCursor().blockNumber()==line
|
|
assert editor._heading_line_for_slug('fake') is None
|
|
finally:editor.close();editor.deleteLater()
|