Skip to content

Commit

Permalink
Adding missing tests for truncate_html_words() (#2918)
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxy4public committed Jul 12, 2023
1 parent ef7e263 commit b8bf595
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pelican/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,26 @@ def test_truncate_html_words(self):
utils.truncate_html_words('<!-- comment -->' + 'word ' * 100, 20),
'<!-- comment -->' + 'word ' * 20 + '…')

# Words enclosed or intervaled by HTML tags with a custom end
# marker containing HTML tags.
self.assertEqual(
utils.truncate_html_words('<p>' + 'word ' * 100 + '</p>', 20,
'<span>marker</span>'),
'<p>' + 'word ' * 20 + '<span>marker</span></p>')
self.assertEqual(
utils.truncate_html_words(
'<span\nstyle="\n\n">' + 'word ' * 100 + '</span>', 20,
'<span>marker</span>'),
'<span\nstyle="\n\n">' + 'word ' * 20 + '<span>marker</span></span>')
self.assertEqual(
utils.truncate_html_words('<br>' + 'word ' * 100, 20,
'<span>marker</span>'),
'<br>' + 'word ' * 20 + '<span>marker</span>')
self.assertEqual(
utils.truncate_html_words('<!-- comment -->' + 'word ' * 100, 20,
'<span>marker</span>'),
'<!-- comment -->' + 'word ' * 20 + '<span>marker</span>')

# Words with hypens and apostrophes.
self.assertEqual(
utils.truncate_html_words("a-b " * 100, 20),
Expand Down

0 comments on commit b8bf595

Please sign in to comment.