Пример #1
0
def test_restore_tags(input):
    r = Richtypo()
    r.text = input

    r.strip_tags()
    r.restore_tags()
    assert r.text == input
Пример #2
0
def test_strip_tags_in_scripts(input, expected):
    r = Richtypo()
    r.text = input
    r.strip_tags()

    expected = re.sub(r'~(\d+)~', '~([^~]+)~', expected)  # it is a regex now
    expected = re.compile(expected)
    assert expected.match(r.text)
Пример #3
0
def test_rule_applying():
    r1 = Rule(pattern='b{2}', replacement='cc')
    r2 = Rule(pattern='c{2}', replacement='dd')

    r = Richtypo()
    r.rules = [r1, r2]
    r.text = 'abb'
    r.apply_rule_chain()

    assert r.text == 'add'
Пример #4
0
def test_rule_order():
    """
    Check if rules are applyied in order they are supplied
    """
    r1 = Rule(pattern='b{2}', replacement='cc')
    r2 = Rule(pattern='c{2}', replacement='dd')
    r = Richtypo()
    r.rules = [r2, r1]  # r2 works only after r1
    r.text = 'abb'
    r.apply_rule_chain()

    assert r.text == 'acc'  # so the text should not be changed
Пример #5
0
def test_strip_tags_when_input_already_contains_richtypo_marks(input, expected):
    r = Richtypo()
    r.text = input
    r.strip_tags()
    r.restore_tags()
    assert r.text == expected