示例#1
0
def test_tag_chars():
    with raises(ValueError):
        am = AnsiMarkup(tag_sep='{')

    with raises(ValueError):
        am = AnsiMarkup(tag_sep='(-)')

    with raises(ValueError):
        am = AnsiMarkup(tag_sep='qq')

    am = AnsiMarkup(tag_sep='{}')

    r1 = p('0<b>1<d>2</d>3</b>4')
    r2 = am.parse('0{b}1{d}2{/d}3{/b}4')
    assert r1 == r2 == '0' + S.BRIGHT + '1' + S.DIM + '2' + S.RESET_ALL + S.BRIGHT + '3' + S.RESET_ALL + '4'

    assert s('<b>1</b>') == am.strip('{b}1{/b}') == '1'
示例#2
0
def test_strip(am):
    assert s('<b>1</b>2<d>3</d>') == '123'
    assert s('<bold,red,yellow>1</bold,red,yellow>') == '1'
    assert s('<r><tag>1</tag></r>') == '<tag>1</tag>'
    assert s('<tag><r>1</r></tag>') == '<tag>1</tag>'
    assert s('<tag><r>1</tag></r>') == '<tag>1</tag>'
    assert s('<r><b>1</r></b>') == '1'
    assert s('<fg red>1<fg red>') == '1'

    am = AnsiMarkup(tags={
        'red': '<red>',
        'b,g,r': '<b,g,r>',
        'fg 1,2,3': '</fg 1,2,3>'
    })
    assert am.strip(
        '<red>1</red><b,g,r>2</b,g,r><fg 1,2,3>3</fg 1,2,3>') == '123'
示例#3
0
def test_tag_chars_conflicting():
    assert p('<r>2 > 1</r>') == F.RED + '2 > 1' + S.RESET_ALL
    assert p('<r>1 < 2</r>') == F.RED + '1 < 2' + S.RESET_ALL
    assert p('<r>1 </ 2</r>') == F.RED + '1 </ 2' + S.RESET_ALL
    assert s('<r>2 > 1</r>') == '2 > 1'
    assert s('<r>1 < 2</r>') == '1 < 2'
    assert s('<r>1 </ 2</r>') == '1 </ 2'

    assert p('{: <10}<r>1</r>') == '{: <10}' + F.RED + '1' + S.RESET_ALL
    assert p('{: </10}<r>1</r>') == '{: </10}' + F.RED + '1' + S.RESET_ALL
    assert s('{: <10}<r>1</r>') == '{: <10}1'
    assert s('{: </10}<r>1</r>') == '{: </10}1'

    assert p('<r>1</r>{: >10}') == F.RED + '1' + S.RESET_ALL + '{: >10}'
    assert s('<r>1</r>{: >10}') == '1{: >10}'

    assert p('<1<r>2</r>3>') == '<1' + F.RED + '2' + S.RESET_ALL + '3>'
    assert p('</1<r>2</r>3>') == '</1' + F.RED + '2' + S.RESET_ALL + '3>'
    assert p('<1<r>2 < 3</r>4>') == '<1' + F.RED + '2 < 3' + S.RESET_ALL + '4>'
    assert p(
        '<1<r>2 </ 3</r>4>') == '<1' + F.RED + '2 </ 3' + S.RESET_ALL + '4>'
    assert p('<1<r>3 > 2</r>4>') == '<1' + F.RED + '3 > 2' + S.RESET_ALL + '4>'
    assert s('<1<r>2</r>3>') == '<123>'
    assert s('</1<r>2</r>3>') == '</123>'
    assert s('<1<r>2 < 3</r>4>') == '<12 < 34>'
    assert s('<1<r>2 </ 3</r>4>') == '<12 </ 34>'
    assert s('<1<r>3 > 2</r>4>') == '<13 > 24>'