diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..7c12820 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +import pytest +import re + +markup_headers = { + 'default': { + 'HEADER1': "= %s =", + 'HEADER2': "== %s ==", + 'HEADER3': "=== %s ===", + }, + 'markdown': { + 'HEADER1': "# %s", + 'HEADER2': "## %s", + 'HEADER3': "### %s", + } +} + + +@pytest.fixture(params=markup_headers) +def test_syntax(request): + markup = request.param + format_header_dict = markup_headers[markup] + + def header_expand(string): + """ + The function perform string replacement of 'HEADER1(.+)' with a header + syntax for a markup containing the string found in '.+'. This function + is constructed with a dict of three header levels containing their regex + and actual syntax. + When a markup is selected and this function is executed, the function + will find instance of 'HEADER1' with 1 being any number between 1 and 3 + inclusive. + """ + for header_level, format_header in format_header_dict.items(): + regex = header_level + '\((.*?)\)' + string = re.sub(regex, + lambda match: format_header % match.group(1), + string) + return string + + return (markup, header_expand) diff --git a/tests/test_syntax_parsing.py b/tests/test_syntax_parsing.py new file mode 100644 index 0000000..b9563e3 --- /dev/null +++ b/tests/test_syntax_parsing.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +import pytest +from taskwiki import regexp +import re + + +class TestParsingSyntax(object): + def test_header(self, test_syntax): + markup, header_expand = test_syntax + header = "HEADER1(Test)" + header = header_expand(header) + + print("Markup: %s,\nHeader syntax:\n%s\nRegex pattern:\n%s" % ( + markup, header, regexp.HEADER[markup].pattern)) + + if re.match(regexp.HEADER[markup], header): + assert 1 + else: + assert 0 + + def test_macro_viewport(self, test_syntax): + markup, header_expand = test_syntax + viewport = "HEADER1(Test | project:Home | +home #T $T)" + viewport = header_expand(viewport) + + print("Viewport syntax:\n%s\nRegex pattern:\n%s" % ( + viewport, regexp.VIEWPORT[markup].pattern)) + + match = re.search(regexp.VIEWPORT[markup], viewport) + + assert match != None + + assert match.group('name').strip() == "Test" + assert match.group('filter').strip() == "project:Home" + assert match.group('defaults').strip() == "+home" + assert match.group('source').strip() == "T" + assert match.group('sort').strip() == "T"