From 89b8d49c53381759a11b7a490454c1f8b3676009 Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 11 Nov 2023 13:37:38 -0600 Subject: [PATCH] test: verify `bot.make_identifier_memory()` behavior w/CASEMAPPING set --- test/test_coretasks.py | 30 ++++++++++++++++++++++++++++++ test/test_irc.py | 15 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/test/test_coretasks.py b/test/test_coretasks.py index c01174e1b..110ceb0d7 100644 --- a/test/test_coretasks.py +++ b/test/test_coretasks.py @@ -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() diff --git a/test/test_irc.py b/test/test_irc.py index 1ea83f32a..e15620a61 100644 --- a/test/test_irc.py +++ b/test/test_irc.py @@ -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