From d93c07144655810da958b8431be86110e7545279 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 26 Aug 2019 16:07:13 -0700 Subject: [PATCH] reverse_modes: test mode cycling with simple modes and bans --- test/protocol_test_fixture.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/protocol_test_fixture.py b/test/protocol_test_fixture.py index 1842df3..b50b5d5 100644 --- a/test/protocol_test_fixture.py +++ b/test/protocol_test_fixture.py @@ -733,4 +733,32 @@ class BaseProtocolTest(unittest.TestCase): out = self.p.reverse_modes('#foobar', '-ovt user user') self.assertEqual(out, '+ot user') # ignore -v + def test_reverse_modes_cycle_simple(self): + c = self.p.channels['#weirdstuff'] = Channel(self.p, name='#weirdstuff') + c.modes = {('t', None), ('n', None)} + + out = self.p.reverse_modes('#weirdstuff', '+n-n') # +- cycle existing mode + self.assertEqual(out, '+n') + out = self.p.reverse_modes('#weirdstuff', '-n+n') # -+ cycle existing mode + self.assertEqual(out, '+n') # Ugly but OK + + out = self.p.reverse_modes('#weirdstuff', '+m-m') # +- cycle non-existent mode + self.assertEqual(out, '-m') + out = self.p.reverse_modes('#weirdstuff', '-m+m') # -+ cycle non-existent mode + self.assertEqual(out, '-m') # Ugly but OK + + def test_reverse_modes_cycle_bans(self): + c = self.p.channels['#weirdstuff'] = Channel(self.p, name='#weirdstuff') + c.modes = {('t', None), ('n', None), ('b', '*!*@test.host')} + + out = self.p.reverse_modes('#weirdstuff', '+b-b *!*@test.host *!*@test.host') # +- cycle existing ban + self.assertEqual(out, '+b *!*@test.host') + out = self.p.reverse_modes('#weirdstuff', '-b+b *!*@test.host *!*@test.host') # -+ cycle existing ban + self.assertEqual(out, '+b *!*@test.host') # Ugly but OK + + out = self.p.reverse_modes('#weirdstuff', '+b-b *!*@* *!*@*') # +- cycle existing ban + self.assertEqual(out, '-b *!*@*') + out = self.p.reverse_modes('#weirdstuff', '-b+b *!*@* *!*@*') # -+ cycle existing ban + self.assertEqual(out, '-b *!*@*') # Ugly but OK + # TODO: test type coersion if channel or mode targets are ints