Another test case for long text

main
Bob Mottram 2020-01-24 11:27:12 +00:00
parent c5b86c1b1d
commit 1bb4e08c35
2 changed files with 12 additions and 6 deletions

View File

@ -273,7 +273,10 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
elif 'dat:' in wordStr: elif 'dat:' in wordStr:
continue continue
if '<' in wordStr: if '<' in wordStr:
wordStr=wordStr.split('<',1)[0] replaceWord=wordStr.split('<',1)[0]
content= \
content.replace(wordStr,replaceWord)
wordStr=replaceWord
if '/' in wordStr: if '/' in wordStr:
continue continue
if len(wordStr[maxWordLength:])<maxWordLength: if len(wordStr[maxWordLength:])<maxWordLength:
@ -285,6 +288,9 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
content= \ content= \
content.replace(wordStr, \ content.replace(wordStr, \
wordStr[:maxWordLength]) wordStr[:maxWordLength])
if content.startswith('<p>'):
if not content.endswith('</p>'):
content=content.strip()+'</p>'
return content return content
def addHtmlTags(baseDir: str,httpPrefix: str, \ def addHtmlTags(baseDir: str,httpPrefix: str, \

View File

@ -1558,6 +1558,10 @@ def testActorParsing():
def testWebLinks(): def testWebLinks():
print('testWebLinks') print('testWebLinks')
exampleText='<p><span class=\"h-card\"><a href=\"https://something/@orother\" class=\"u-url mention\">@<span>foo</span></a></span> Some random text.</p><p>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p>'
resultText=removeLongWords(exampleText,40,[])
assert resultText=='<p><span class="h-card"><a href="https://something/@orother" class="u-url mention">@<span>foo</span></a></span> Some random text.</p>'
exampleText='This post has a web links https://somesite.net\n\nAnd some other text' exampleText='This post has a web links https://somesite.net\n\nAnd some other text'
linkedText=addWebLinks(exampleText) linkedText=addWebLinks(exampleText)
assert '<a href="https://somesite.net" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">somesite.net</span></a' in linkedText assert '<a href="https://somesite.net" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">somesite.net</span></a' in linkedText
@ -1574,10 +1578,6 @@ def testWebLinks():
resultText=removeLongWords(exampleText,40,[]) resultText=removeLongWords(exampleText,40,[])
assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>' assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>'
exampleText='<p>Some text.\n\nHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAH!</p>'
resultText=removeLongWords(exampleText,40,[])
assert resultText=='<p>Some text.\n\nHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH</p>'
def testAddEmoji(): def testAddEmoji():
print('testAddEmoji') print('testAddEmoji')
@ -1693,13 +1693,13 @@ def testRecentPostsCache():
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')
testWebLinks()
testRecentPostsCache() testRecentPostsCache()
testTheme() testTheme()
testSaveLoadJson() testSaveLoadJson()
testCommentJson() testCommentJson()
testGetStatusNumber() testGetStatusNumber()
testAddEmoji() testAddEmoji()
testWebLinks()
testActorParsing() testActorParsing()
testHttpsig() testHttpsig()
testCache() testCache()