import pytest


@pytest.mark.parametrize(
    "in_,out_unicode, out_html",
    [
        ("", "", ""),
        (" ", " ", " "),
        ("A very simple test", "A very simple\u00a0test", "A very simple&nbsp;test"),
        ("Test", "Test", "Test"),
        (" Test", " Test", " Test"),
        (
            "<ul><li>Test</p></li><ul>",
            "<ul><li>Test</p></li><ul>",
            "<ul><li>Test</p></li><ul>",
        ),
        (
            "<ul><li> Test</p></li><ul>",
            "<ul><li> Test</p></li><ul>",
            "<ul><li> Test</p></li><ul>",
        ),
        (
            "<p>In a couple of paragraphs</p><p>paragraph two</p>",
            "<p>In a couple of\u00a0paragraphs</p><p>paragraph\u00a0two</p>",
            "<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>",
        ),
        (
            '<h1><a href="#">In a link inside a heading</i> </a></h1>',
            '<h1><a href="#">In a link inside a\u00a0heading</i> </a></h1>',
            '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>',
        ),
        (
            '<h1><a href="#">In a link</a> followed by other text</h1>',
            '<h1><a href="#">In a link</a> followed by other\u00a0text</h1>',
            '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>',
        ),
        (
            '<h1><a href="#"></a></h1>',
            '<h1><a href="#"></a></h1>',
            '<h1><a href="#"></a></h1>',
        ),
        (
            "<div>Divs get no love!</div>",
            "<div>Divs get no love!</div>",
            "<div>Divs get no love!</div>",
        ),
        (
            "<pre>Neither do PREs</pre>",
            "<pre>Neither do PREs</pre>",
            "<pre>Neither do PREs</pre>",
        ),
        (
            "<div><p>But divs with paragraphs do!</p></div>",
            "<div><p>But divs with paragraphs\u00a0do!</p></div>",
            "<div><p>But divs with paragraphs&nbsp;do!</p></div>",
        ),
        (
            "<p>With <mark>my friend Mark.</mark></p>",
            "<p>With <mark>my friend\u00a0Mark.</mark></p>",
            "<p>With <mark>my friend&nbsp;Mark.</mark></p>",
        ),
        (
            "Really. Good.",
            "Really. Good.",
            "Really. Good.",
        ),
        (
            "With, punctuation",
            "With, punctuation",
            "With, punctuation",
        ),
        (
            "<details><summary>Unfold for content</summary></details>",
            "<details><summary>Unfold for\u00a0content</summary></details>",
            "<details><summary>Unfold for&nbsp;content</summary></details>",
        ),
        # TODISCUSS: we probably want to widont the summary too?
        (
            "<details><summary>Unfold for content</summary><p>This is the content.</p></details>",
            "<details><summary>Unfold for content</summary><p>This is the\u00a0content.</p></details>",
            "<details><summary>Unfold for content</summary><p>This is the&nbsp;content.</p></details>",
        ),
    ],
)
def test_widont(in_, out_unicode, out_html):
    from widont import widont

    assert widont(in_) == out_unicode
    assert widont(out_unicode) == out_unicode
    assert widont(in_, html=True) == out_html
    # TODO
    # assert widont(out_html, html=True) == out_html
