Skip to content

Commit

Permalink
test: verify more find behaviors
Browse files Browse the repository at this point in the history
Check that correcting someone else's line works as expected, and check
that replacing an already-replaced line works as expected.

Also check that case-insensitive (i) and global (g) flags work as
expected, both separately and together.

Note: There is a glitch in formatting when the new replacement occurs
inside the previous one, since the bolding used to indicate what changed
is kept in the stored line. We might wish to fix that at some point, but
the new test correctly represents the real behavior.
  • Loading branch information
dgw committed Sep 2, 2024
1 parent bba3bd1 commit 2ed6c7d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/builtins/test_builtins_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def user(userfactory):
return userfactory('User')


@pytest.fixture
def other_user(userfactory):
return userfactory('other_user')


@pytest.fixture
def channel():
return '#testing'
Expand All @@ -44,11 +49,15 @@ def channel():
("A piped line.", r"s|line|replacement|", f"A piped {bold('replacement')}."),
("An escaped | line.", r"s|\||pipe|", f"An escaped {bold('pipe')} line."),
("An escaped \\ line.", r"s/\\/backslash/", f"An escaped {bold('backslash')} line."),
("abABab", r"s/b/c/g", "abABab".replace('b', bold('c'))), # g (global) flag
("ABabAB", r"s/b/c/i", f"A{bold('c')}abAB"), # i (case-insensitive) flag
("ABabAB", r"s/b/c/ig", f"A{bold('c')}a{bold('c')}A{bold('c')}"), # both flags
)


@pytest.mark.parametrize('original, command, result', REPLACES_THAT_WORK)
def test_valid_replacements(bot, irc, user, channel, original, command, result):
"""Verify that basic replacement functionality works."""
irc.channel_joined(channel, [user.nick])

irc.say(user, channel, original)
Expand All @@ -59,3 +68,42 @@ def test_valid_replacements(bot, irc, user, channel, original, command, result):
assert bot.backend.message_sent == rawlist(
"PRIVMSG %s :%s meant to say: %s" % (channel, user.nick, result),
)


def test_multiple_users(bot, irc, user, other_user, channel):
"""Verify that correcting another user's line works."""
irc.channel_joined(channel, [user.nick, other_user.nick])

irc.say(other_user, channel, 'Some weather we got yesterday')
irc.say(user, channel, '%s: s/yester/to/' % other_user.nick)

assert len(bot.backend.message_sent) == 1, (
"The bot should respond with exactly one line.")
assert bot.backend.message_sent == rawlist(
"PRIVMSG %s :%s thinks %s meant to say: %s" % (
channel, user.nick, other_user.nick,
f"Some weather we got {bold('to')}day",
),
)


def test_replace_the_replacement(bot, irc, user, channel):
"""Verify replacing text that was already replaced."""
irc.channel_joined(channel, [user.nick])

irc.say(user, channel, 'spam')
irc.say(user, channel, 's/spam/eggs/')
irc.say(user, channel, 's/eggs/bacon/')

assert len(bot.backend.message_sent) == 2, (
"The bot should respond twice.")
assert bot.backend.message_sent == rawlist(
"PRIVMSG %s :%s meant to say: %s" % (
channel, user.nick, bold('eggs'),
),
"PRIVMSG %s :%s meant to say: %s" % (
channel, user.nick, bold(bold('bacon')),
# the test is accurate, even though the behavior here (doubled bold
# control characters) is less than ideal
),
)

0 comments on commit 2ed6c7d

Please sign in to comment.