Skip to content

Commit

Permalink
Merge pull request #2505 from sopel-irc/cap-trailing-space
Browse files Browse the repository at this point in the history
test: add capabilities test cases for trailing space handling
  • Loading branch information
dgw authored Sep 16, 2023
2 parents bc688b4 + 0c86842 commit 274470e
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 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,7 +209,19 @@ def test_capabilities_nak(mockbot, triggerfactory):
assert not manager.enabled


def test_capabilities_nack_multiple(mockbot, triggerfactory):
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_nak_multiple(mockbot, triggerfactory):
raw = 'CAP * NAK :away-notify account-tag'
wrapped = triggerfactory.wrapper(mockbot, raw)
manager = Capabilities()
Expand All @@ -208,7 +246,7 @@ def test_capabilities_nack_multiple(mockbot, triggerfactory):
assert not manager.enabled


def test_capabilities_ack_and_nack(mockbot, triggerfactory):
def test_capabilities_ack_and_nak(mockbot, triggerfactory):
manager = Capabilities()

# ACK a single CAP
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 274470e

Please sign in to comment.