Repository with sources and generator of https://larlet.fr/david/ https://larlet.fr/david/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

test_widont.py 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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>With <mark>my friend Mark.</mark></p>",
  57. "<p>With <mark>my friend\u00a0Mark.</mark></p>",
  58. "<p>With <mark>my friend&nbsp;Mark.</mark></p>",
  59. ),
  60. (
  61. "Really. Good.",
  62. "Really. Good.",
  63. "Really. Good.",
  64. ),
  65. (
  66. "With, punctuation",
  67. "With, punctuation",
  68. "With, punctuation",
  69. ),
  70. (
  71. "<details><summary>Unfold for content</summary></details>",
  72. "<details><summary>Unfold for\u00a0content</summary></details>",
  73. "<details><summary>Unfold for&nbsp;content</summary></details>",
  74. ),
  75. # TODISCUSS: we probably want to widont the summary too?
  76. (
  77. "<details><summary>Unfold for content</summary><p>This is the content.</p></details>",
  78. "<details><summary>Unfold for content</summary><p>This is the\u00a0content.</p></details>",
  79. "<details><summary>Unfold for content</summary><p>This is the&nbsp;content.</p></details>",
  80. ),
  81. ],
  82. )
  83. def test_widont(in_, out_unicode, out_html):
  84. from widont import widont
  85. assert widont(in_) == out_unicode
  86. assert widont(out_unicode) == out_unicode
  87. assert widont(in_, html=True) == out_html
  88. # TODO
  89. # assert widont(out_html, html=True) == out_html