Skip to content

Commit

Permalink
test: add capabilities test cases for trailing space handling
Browse files Browse the repository at this point in the history
Some IRCds include trailing space in capability lists, and this is not a
spec violation. Default `.split()` behavior in Python should handle it
fine, but it's also good to be explicit that we expect the default
behavior, through tests.
  • Loading branch information
dgw committed Sep 4, 2023
1 parent bc688b4 commit 495ce9c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/irc/test_irc_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ def test_capabilities_ls_multiline(mockbot, triggerfactory):
assert manager.available == {'away-notify': None, 'account-tag': None}


def test_capabilities_ls_trailing_space(mockbot, triggerfactory: TriggerFactory):
raw = 'CAP * LS :away-notify '
wrapped = triggerfactory.wrapper(mockbot, raw)
manager = Capabilities()
assert manager.handle_ls(wrapped, wrapped._trigger)
assert manager.is_available('away-notify')
assert not manager.is_enabled('away-notify')
assert manager.available == {'away-notify': None}
assert not manager.enabled

expected = CapabilityInfo('away-notify', None, True, False)
assert manager.get_capability_info('away-notify') == expected


def test_capabilities_ack(mockbot, triggerfactory):
raw = 'CAP * ACK :away-notify'
wrapped = triggerfactory.wrapper(mockbot, raw)
Expand All @@ -104,6 +118,18 @@ def test_capabilities_ack(mockbot, triggerfactory):
assert manager.enabled == frozenset({'away-notify', 'account-tag'})


def test_capabilities_ack_trailing_space(mockbot, triggerfactory):
raw = 'CAP * ACK :away-notify '
wrapped = triggerfactory.wrapper(mockbot, raw)
manager = Capabilities()
assert manager.handle_ack(wrapped, wrapped._trigger) == ('away-notify',)
assert not manager.is_available('away-notify'), (
'ACK a capability does not update server availability.')
assert manager.is_enabled('away-notify'), (
'ACK a capability make it enabled.')
assert manager.enabled == frozenset({'away-notify'})


def test_capabilities_ack_multiple(mockbot, triggerfactory):
raw = 'CAP * ACK :away-notify account-tag'
wrapped = triggerfactory.wrapper(mockbot, raw)
Expand Down Expand Up @@ -183,6 +209,18 @@ def test_capabilities_nak(mockbot, triggerfactory):
assert not manager.enabled


def test_capabilities_nak_trailing_space(mockbot, triggerfactory):
raw = 'CAP * NAK :away-notify '
wrapped = triggerfactory.wrapper(mockbot, raw)
manager = Capabilities()
assert manager.handle_nak(wrapped, wrapped._trigger) == ('away-notify',)
assert not manager.is_available('away-notify'), (
'NAK a capability does not update server availability.')
assert not manager.is_enabled('away-notify'), (
'NAK a capability make it not enabled.')
assert not manager.enabled


def test_capabilities_nack_multiple(mockbot, triggerfactory):
raw = 'CAP * NAK :away-notify account-tag'
wrapped = triggerfactory.wrapper(mockbot, raw)
Expand Down Expand Up @@ -274,6 +312,21 @@ def test_capabilities_new(mockbot, triggerfactory):
assert not manager.enabled


def test_capabilities_new_trailing_space(mockbot, triggerfactory):
manager = Capabilities()

# NEW CAP
raw = 'CAP * NEW :echo-message '
wrapped = triggerfactory.wrapper(mockbot, raw)
assert manager.handle_new(wrapped, wrapped._trigger) == (
'echo-message',
)
assert manager.is_available('echo-message')
assert not manager.is_enabled('echo-message')
assert manager.available == {'echo-message': None}
assert not manager.enabled


def test_capabilities_new_multiple(mockbot, triggerfactory):
manager = Capabilities()

Expand Down Expand Up @@ -320,6 +373,21 @@ def test_capabilities_del(mockbot, triggerfactory):
assert not manager.enabled


def test_capabilities_del_trailing_space(mockbot, triggerfactory):
manager = Capabilities()

# DEL CAP
raw = 'CAP * DEL :echo-message '
wrapped = triggerfactory.wrapper(mockbot, raw)
assert manager.handle_del(wrapped, wrapped._trigger) == (
'echo-message',
)
assert not manager.is_available('echo-message')
assert not manager.is_enabled('echo-message')
assert not manager.available
assert not manager.enabled


def test_capabilities_del_available(mockbot, triggerfactory):
manager = Capabilities()

Expand Down

0 comments on commit 495ce9c

Please sign in to comment.