Repository with sources and generator of https://larlet.fr/david/ https://larlet.fr/david/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test_widont.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. (
  78. "<details><summary>Unfold for content</summary>"
  79. "<p>This is the content.</p></details>"
  80. ),
  81. (
  82. "<details><summary>Unfold for content</summary>"
  83. "<p>This is the\u00a0content.</p></details>"
  84. ),
  85. (
  86. "<details><summary>Unfold for content</summary>"
  87. "<p>This is the&nbsp;content.</p></details>"
  88. ),
  89. ),
  90. ],
  91. )
  92. def test_widont(in_, out_unicode, out_html):
  93. from widont import widont
  94. assert widont(in_) == out_unicode
  95. assert widont(out_unicode) == out_unicode
  96. assert widont(in_, html=True) == out_html
  97. # TODO
  98. # assert widont(out_html, html=True) == out_html