Added tests of comment merging.
Tweaked comment merging to pass tests.
This commit is contained in:
parent
b8aa11e5ce
commit
fb3a7ec2da
|
@ -290,6 +290,10 @@ def merge_comments(oldcomment:str, newcomment:str) -> str:
|
|||
if oldcomment == newcomment or newcomment in ['', None]:
|
||||
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
|
||||
# re-concatenating the same strings every time there's an
|
||||
# update, causing the comment to grow without bound.
|
||||
|
|
|
@ -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'
|
Loading…
Reference in New Issue