Skip to content

Commit 2ed6c7d

Browse files
committed
test: verify more find behaviors
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.
1 parent bba3bd1 commit 2ed6c7d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/builtins/test_builtins_find.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def user(userfactory):
3333
return userfactory('User')
3434

3535

36+
@pytest.fixture
37+
def other_user(userfactory):
38+
return userfactory('other_user')
39+
40+
3641
@pytest.fixture
3742
def channel():
3843
return '#testing'
@@ -44,11 +49,15 @@ def channel():
4449
("A piped line.", r"s|line|replacement|", f"A piped {bold('replacement')}."),
4550
("An escaped | line.", r"s|\||pipe|", f"An escaped {bold('pipe')} line."),
4651
("An escaped \\ line.", r"s/\\/backslash/", f"An escaped {bold('backslash')} line."),
52+
("abABab", r"s/b/c/g", "abABab".replace('b', bold('c'))), # g (global) flag
53+
("ABabAB", r"s/b/c/i", f"A{bold('c')}abAB"), # i (case-insensitive) flag
54+
("ABabAB", r"s/b/c/ig", f"A{bold('c')}a{bold('c')}A{bold('c')}"), # both flags
4755
)
4856

4957

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

5463
irc.say(user, channel, original)
@@ -59,3 +68,42 @@ def test_valid_replacements(bot, irc, user, channel, original, command, result):
5968
assert bot.backend.message_sent == rawlist(
6069
"PRIVMSG %s :%s meant to say: %s" % (channel, user.nick, result),
6170
)
71+
72+
73+
def test_multiple_users(bot, irc, user, other_user, channel):
74+
"""Verify that correcting another user's line works."""
75+
irc.channel_joined(channel, [user.nick, other_user.nick])
76+
77+
irc.say(other_user, channel, 'Some weather we got yesterday')
78+
irc.say(user, channel, '%s: s/yester/to/' % other_user.nick)
79+
80+
assert len(bot.backend.message_sent) == 1, (
81+
"The bot should respond with exactly one line.")
82+
assert bot.backend.message_sent == rawlist(
83+
"PRIVMSG %s :%s thinks %s meant to say: %s" % (
84+
channel, user.nick, other_user.nick,
85+
f"Some weather we got {bold('to')}day",
86+
),
87+
)
88+
89+
90+
def test_replace_the_replacement(bot, irc, user, channel):
91+
"""Verify replacing text that was already replaced."""
92+
irc.channel_joined(channel, [user.nick])
93+
94+
irc.say(user, channel, 'spam')
95+
irc.say(user, channel, 's/spam/eggs/')
96+
irc.say(user, channel, 's/eggs/bacon/')
97+
98+
assert len(bot.backend.message_sent) == 2, (
99+
"The bot should respond twice.")
100+
assert bot.backend.message_sent == rawlist(
101+
"PRIVMSG %s :%s meant to say: %s" % (
102+
channel, user.nick, bold('eggs'),
103+
),
104+
"PRIVMSG %s :%s meant to say: %s" % (
105+
channel, user.nick, bold(bold('bacon')),
106+
# the test is accurate, even though the behavior here (doubled bold
107+
# control characters) is less than ideal
108+
),
109+
)

0 commit comments

Comments
 (0)