Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add capabilities test cases for trailing space handling #2505

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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