Repository with sources and generator of https://larlet.fr/david/ https://larlet.fr/david/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_widont.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import pytest
  2. @pytest.mark.parametrize(
  3. "in_,out_unicode, out_html",
  4. [
  5. ("", "", ""),
  6. (" ", " ", " "),
  7. ("A very simple test", "A very simple\u00a0test", "A very simple test"),
  8. ("Test", "Test", "Test"),
  9. (" Test", " Test", " Test"),
  10. (
  11. "<ul><li>Test</p></li><ul>",
  12. "<ul><li>Test</p></li><ul>",
  13. "<ul><li>Test</p></li><ul>",
  14. ),
  15. (
  16. "<ul><li> Test</p></li><ul>",
  17. "<ul><li> Test</p></li><ul>",
  18. "<ul><li> Test</p></li><ul>",
  19. ),
  20. (
  21. "<p>In a couple of paragraphs</p><p>paragraph two</p>",
  22. "<p>In a couple of\u00a0paragraphs</p><p>paragraph\u00a0two</p>",
  23. "<p>In a couple of&nbsp;paragraphs</p><p>paragraph&nbsp;two</p>",
  24. ),
  25. (
  26. '<h1><a href="#">In a link inside a heading</i> </a></h1>',
  27. '<h1><a href="#">In a link inside a\u00a0heading</i> </a></h1>',
  28. '<h1><a href="#">In a link inside a&nbsp;heading</i> </a></h1>',
  29. ),
  30. (
  31. '<h1><a href="#">In a link</a> followed by other text</h1>',
  32. '<h1><a href="#">In a link</a> followed by other\u00a0text</h1>',
  33. '<h1><a href="#">In a link</a> followed by other&nbsp;text</h1>',
  34. ),
  35. (
  36. '<h1><a href="#"></a></h1>',
  37. '<h1><a href="#"></a></h1>',
  38. '<h1><a href="#"></a></h1>',
  39. ),
  40. (
  41. "<div>Divs get no love!</div>",
  42. "<div>Divs get no love!</div>",
  43. "<div>Divs get no love!</div>",
  44. ),
  45. (
  46. "<pre>Neither do PREs</pre>",
  47. "<pre>Neither do PREs</pre>",
  48. "<pre>Neither do PREs</pre>",
  49. ),
  50. (
  51. "<div><p>But divs with paragraphs do!</p></div>",
  52. "<div><p>But divs with paragraphs\u00a0do!</p></div>",
  53. "<div><p>But divs with paragraphs&nbsp;do!</p></div>",
  54. ),
  55. (
  56. "<p>Avec <mark>mon ami Marc.</mark></p>",
  57. "<p>Avec <mark>mon ami\u00a0Marc.</mark></p>",
  58. "<p>Avec <mark>mon ami&nbsp;Marc.</mark></p>",
  59. ),
  60. (
  61. "Vraiment. Bien.",
  62. "Vraiment. Bien.",
  63. "Vraiment. Bien.",
  64. ),
  65. ],
  66. )
  67. def test_widont(in_, out_unicode, out_html):
  68. from widont import widont
  69. assert widont(in_) == out_unicode
  70. assert widont(out_unicode) == out_unicode
  71. assert widont(in_, html=True) == out_html
  72. # TODO
  73. # assert widont(out_html, html=True) == out_html