Skip to content

Commit

Permalink
test: verify bot.make_identifier_memory() behavior w/CASEMAPPING set
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed Nov 11, 2023
1 parent 46977b6 commit 89b8d49
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ def test_handle_isupport_casemapping(mockbot):
assert mockbot.nick.lower() == 'test[a]'


def test_handle_isupport_casemapping_identifiermemory(mockbot):
# create a nick that needs casemapping
rfc1459 = 'Test[a]'

# create `SopelIdentifierMemory` w/bot's helper method and add the nick
memory = mockbot.make_identifier_memory()
memory[rfc1459] = rfc1459

# check default behavior (`rfc1459` casemapping)
assert memory['test{a}'] == rfc1459
assert memory['Test[a]'] == rfc1459

# now the bot "connects" to a server using `CASEMAPPING=ascii`
mockbot.on_message(
':irc.example.com 005 Sopel '
'CHANTYPES=# EXCEPTS INVEX CHANMODES=eIbq,k,flj,CFLMPQScgimnprstz '
'CHANLIMIT=#:120 PREFIX=(ov)@+ MAXLIST=bqeI:100 MODES=4 '
'NETWORK=example STATUSMSG=@+ CALLERID=g CASEMAPPING=ascii '
':are supported by this server')

# CASEMAPPING token change doesn't affect previously existing Identifiers...
assert memory['Test{a}'] == rfc1459
# ...so we have to create a new nick that will casemap differently now
ascii = 'Test[b]'
memory[ascii] = ascii
assert len(memory) == 2
assert memory['test[b]'] == ascii
assert 'test{b}' not in memory


def test_handle_isupport_chantypes(mockbot):
# check default behavior (chantypes allows #, &, +, and !)
assert not mockbot.make_identifier('#channel').is_nick()
Expand Down
15 changes: 15 additions & 0 deletions test/test_irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ def bot(tmpconfig, botfactory):
return botfactory(tmpconfig)


def test_make_identifier(bot):
nick = bot.make_identifier('Test[a]')
assert 'test{a}' == nick


def test_make_identifier_memory(bot):
memory = bot.make_identifier_memory()
memory['Test[a]'] = True
assert memory['test{a}'] is True

memory['test{a}'] = False
assert len(memory) == 1
assert memory['Test[a]'] is False


def prefix_length(bot):
# ':', nick, '!', '~', ident/username, '@', maximum hostname length, <0x20>
return 1 + len(bot.nick) + 1 + 1 + len(bot.user) + 1 + 63 + 1
Expand Down

0 comments on commit 89b8d49

Please sign in to comment.