From 1bb4e08c3558a526c164a7b802fef669a95933c5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 24 Jan 2020 11:27:12 +0000 Subject: [PATCH] Another test case for long text --- content.py | 8 +++++++- tests.py | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/content.py b/content.py index 25124549..8f8f4612 100644 --- a/content.py +++ b/content.py @@ -273,7 +273,10 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str: elif 'dat:' in wordStr: continue if '<' in wordStr: - wordStr=wordStr.split('<',1)[0] + replaceWord=wordStr.split('<',1)[0] + content= \ + content.replace(wordStr,replaceWord) + wordStr=replaceWord if '/' in wordStr: continue if len(wordStr[maxWordLength:]) str: content= \ content.replace(wordStr, \ wordStr[:maxWordLength]) + if content.startswith('

'): + if not content.endswith('

'): + content=content.strip()+'

' return content def addHtmlTags(baseDir: str,httpPrefix: str, \ diff --git a/tests.py b/tests.py index f677ffcb..a9e066f3 100644 --- a/tests.py +++ b/tests.py @@ -1558,6 +1558,10 @@ def testActorParsing(): def testWebLinks(): print('testWebLinks') + exampleText='

@foo Some random text.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

' + resultText=removeLongWords(exampleText,40,[]) + assert resultText=='

@foo Some random text.

' + exampleText='This post has a web links https://somesite.net\n\nAnd some other text' linkedText=addWebLinks(exampleText) assert 'somesite.netABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>' - exampleText='

Some text.\n\nHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAH!

' - resultText=removeLongWords(exampleText,40,[]) - assert resultText=='

Some text.\n\nHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH

' - def testAddEmoji(): print('testAddEmoji') @@ -1693,13 +1693,13 @@ def testRecentPostsCache(): def runAllTests(): print('Running tests...') + testWebLinks() testRecentPostsCache() testTheme() testSaveLoadJson() testCommentJson() testGetStatusNumber() testAddEmoji() - testWebLinks() testActorParsing() testHttpsig() testCache()