Adding missing tests for truncate_html_words() (#2918)

This commit is contained in:
(GalaxyMaster) 2023-07-12 19:28:26 +10:00 committed by GitHub
commit b8bf5950b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,6 +259,26 @@ class TestUtils(LoggedTestCase):
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),