eorg/tests/test_regex.py

79 lines
1.7 KiB
Python

import os
import re
import pytest
from eorg import const
from eorg.parser import parse
from eorg.generate import html
def test_meta_headers():
text = "#+TITLE: test title"
rx = const.t_META
match = re.search(rx, text)
assert match is not None
text = "#+UNKNOWN: test title"
rx = const.t_META
match = re.search(rx, text)
assert match is None
text = "#+UNKNOWN: test title"
rx = const.t_META_OTHER
match = re.search(rx, text)
assert match is not None
def test_example():
text = "#+BEGIN_EXAMPLE"
rx = const.t_EXAMPLE_BEGIN
match = re.search(rx, text)
assert match is not None
text = "#+BEGIN_EXAMPLE "
rx = const.t_EXAMPLE_BEGIN
match = re.search(rx, text)
assert match is not None
def test_source():
# invalid if no language specified
text = "#+BEGIN_SRC"
rx = const.t_SRC_BEGIN
match = re.search(rx, text)
assert match is None
text = "#+BEGIN_SRC "
rx = const.t_SRC_BEGIN
match = re.search(rx, text)
assert match is not None
text = "#+BEGIN_SRC sh :results silent"
rx = const.t_SRC_BEGIN
match = re.search(rx, text)
assert match is not None
def test_bullets():
# invalid if no language specified
text = " + bullet 1"
rx = const.t_BULLET_START
match = re.search(rx, text)
assert match is not None
text = "+ bullet 1"
rx = const.t_BULLET_START
match = re.search(rx, text)
assert match is not None
def test_captions_regex():
text = "#+CAPTION: Test"
rx = const.t_CAPTIONS
match = re.search(rx, text)
assert match is not None
text = "#+CAPTION:Test"
rx = const.t_CAPTIONS
match = re.search(rx, text)
assert match is not None