Completed
Push — main ( 39501b...4a0798 )
by Jochen
05:29
created

test_image()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
import pytest
7
8
from byceps.services.text_markup.service import render_html
9
10
11
def test_auto_url_linking():
12
    text = 'before http://example.com/index.html after'
13
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">http://example.com/index.html</a> after'
14
    assert render_html(text) == expected
15
16
17
def test_code_block():
18
    text = 'Use the source, Luke!\n[code]Do not replace ... with an ellipsis character![/code]\nSweet!'
19
    expected = 'Use the source, Luke!<br /><pre><code class="block">Do not replace ... with an ellipsis character!</code></pre><br />Sweet!'
20
    assert render_html(text) == expected
21
22
23
def test_explicit_url_linking():
24
    text = 'before [url]http://example.com/index.html[/url] after'
25
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">http://example.com/index.html</a> after'
26
    assert render_html(text) == expected
27
28
29
def test_explicit_url_linking_applies_no_cosmetics():
30
    text = 'before [url]http://example.com/dash--dash.html[/url] after'
31
    expected = 'before <a rel="nofollow" href="http://example.com/dash--dash.html">http://example.com/dash--dash.html</a> after'
32
    assert render_html(text) == expected
33
34
35
def test_labeled_url_linking():
36
    text = 'before [url=http://example.com/index.html]Example[/url] after'
37
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">Example</a> after'
38
    assert render_html(text) == expected
39
40
41
def test_image():
42
    text = 'before [img]http://example.com/image.png[/img] after'
43
    expected = 'before <img src="http://example.com/image.png"> after'
44
    assert render_html(text) == expected
45
46
47
def test_image_applies_no_cosmetics():
48
    text = '[img]http://example.com/double--dash.png[/img]'
49
    expected = '<img src="http://example.com/double--dash.png">'
50
    assert render_html(text) == expected
51
52
53
def test_linked_image():
54
    text = 'before [url=http://example.com/index.html][img]http://example.com/image.png[/img][/url] after'
55
    expected = 'before <a rel="nofollow" href="http://example.com/index.html"><img src="http://example.com/image.png"></a> after'
56
    assert render_html(text) == expected
57
58
59
def test_quote_without_author():
60
    text = '[quote]All your base are belong to us.[/quote]'
61
    expected = '<blockquote>All your base are belong to us.</blockquote>'
62
    assert render_html(text) == expected
63
64
65
def test_quote_with_author():
66
    text = '[quote author="CATS"]All your base are belong to us.[/quote]'
67
    expected = '<p class="quote-intro"><cite>CATS</cite> schrieb:</p>\n<blockquote>All your base are belong to us.</blockquote>'
68
    assert render_html(text) == expected
69
70
71
@pytest.mark.parametrize(
72
    'text, expected',
73
    [
74
        (
75
            '[quote author="foo]bar"]blah[/quote]',
76
            '<p class="quote-intro"><cite>foo]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
77
        ),
78
        (
79
            '[quote author="foo[bar"]blah[/quote]',
80
            '<p class="quote-intro"><cite>foo[bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
81
        ),
82
        (
83
            '[quote author="foo][bar"]blah[/quote]',
84
            '<p class="quote-intro"><cite>foo][bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
85
        ),
86
        (
87
            '[quote author="foo[]bar"]blah[/quote]',
88
            '<p class="quote-intro"><cite>foo[]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
89
        ),
90
        (
91
            '[quote author="[foobar]"]blah[/quote]',
92
            '<p class="quote-intro"><cite>[foobar]</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
93
        ),
94
        (
95
            '[quote author="]foobar["]blah[/quote]',
96
            '<p class="quote-intro"><cite>]foobar[</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
97
        ),
98
        (
99
            '[quote author="<AngleBracketeer>"]careful.[/quote]',
100
            '<p class="quote-intro"><cite>&lt;AngleBracketeer&gt;</cite> schrieb:</p>\n<blockquote>careful.</blockquote>',
101
        ),
102
    ],
103
)
104
def test_quote_with_author_whose_name_contains_square_brackets(text, expected):
105
    assert render_html(text) == expected
106