Added tests of comment merging.

Tweaked comment merging to pass tests.
This commit is contained in:
Justin Warren 2023-01-22 13:25:40 +11:00
parent b8aa11e5ce
commit fb3a7ec2da
No known key found for this signature in database
2 changed files with 72 additions and 0 deletions

View File

@ -290,6 +290,10 @@ def merge_comments(oldcomment:str, newcomment:str) -> str:
if oldcomment == newcomment or newcomment in ['', None]: if oldcomment == newcomment or newcomment in ['', None]:
return oldcomment return oldcomment
# If old comment is empty, just return the new one
if oldcomment in ['', None]:
return newcomment
# We want to skip duplicate fragments so we don't end up # We want to skip duplicate fragments so we don't end up
# re-concatenating the same strings every time there's an # re-concatenating the same strings every time there's an
# update, causing the comment to grow without bound. # update, causing the comment to grow without bound.

View File

@ -0,0 +1,68 @@
""" Test merging of comments
"""
import pytest
from fediblockhole import merge_comments
def test_merge_blank_comments():
oldcomment = ''
newcomment = ''
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == ''
def test_merge_None_comments():
oldcomment = None
newcomment = None
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == ''
def test_merge_oldstr_newNone():
oldcomment = 'fred, bibble'
newcomment = None
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_oldempty_newcomment():
oldcomment = ''
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_oldNone_newcomment():
oldcomment = None
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_two_different():
oldcomment = 'happy, medium, spinning'
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'happy, medium, spinning, fred, bibble'
def test_merge_overlaps():
oldcomment = 'happy, medium, spinning'
newcomment = 'fred, medium, bibble, spinning'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'happy, medium, spinning, fred, bibble'