diff options
Diffstat (limited to 'tests/lsp_tests/test_lsp_dctrl.py')
-rw-r--r-- | tests/lsp_tests/test_lsp_dctrl.py | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/tests/lsp_tests/test_lsp_dctrl.py b/tests/lsp_tests/test_lsp_dctrl.py index 2bc90ba..e93ba17 100644 --- a/tests/lsp_tests/test_lsp_dctrl.py +++ b/tests/lsp_tests/test_lsp_dctrl.py @@ -1,4 +1,7 @@ import textwrap +from typing import Optional + +import pytest from debputy.lsp.debputy_ls import DebputyLanguageServer @@ -56,6 +59,165 @@ def test_dctrl_complete_field(ls: "DebputyLanguageServer") -> None: assert "Package" not in keywords assert "Source" not in keywords + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + Source: foo + + Package: foo + <CURSOR> + Architecture: any +""" + ), + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert "Multi-Arch" in keywords + # Should be considered present even though it is parsed as two stanzas with a space + assert "Architecture" not in keywords + # Already present or wrong section + assert "Package" not in keywords + assert "Source" not in keywords + + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + Source: foo + + Package: foo + Sec<CURSOR> + Architecture: any +""" + ), + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + # Included since we rely on client filtering (some clients let "RRR" match "R(ules-)R(equires-)R(oot), etc). + assert "Multi-Arch" in keywords + # Should be considered present even though it is parsed as two stanzas with an error + assert "Architecture" not in keywords + # Already present or wrong section + assert "Package" not in keywords + assert "Source" not in keywords + + +@pytest.mark.parametrize( + "case,is_arch_all", + [ + ("Architecture: any\n<CURSOR>", False), + ("Architecture: any\nM-A<CURSOR>", False), + ("<CURSOR>\nArchitecture: any", False), + ("M-A<CURSOR>\nArchitecture: any", False), + ("Architecture: all\n<CURSOR>", True), + ("Architecture: all\nM-A<CURSOR>", True), + ("<CURSOR>\nArchitecture: all", True), + ("M-A<CURSOR>\nArchitecture: all", True), + # Does not have architecture + ("M-A<CURSOR>", None), + ], +) +def test_dctrl_complete_field_context( + ls: "DebputyLanguageServer", + case: str, + is_arch_all: Optional[bool], +) -> None: + dctrl_uri = "file:///nowhere/debian/control" + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + {CASE} +""" + ).format(CASE=case) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + # Missing Architecture counts as "arch:all" by the completion logic + if is_arch_all is False: + assert "X-DH-Build-For-Type" in keywords + else: + assert "X-DH-Build-For-Type" not in keywords + + +def test_dctrl_complete_field_value_context(ls: "DebputyLanguageServer") -> None: + dctrl_uri = "file:///nowhere/debian/control" + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + Architecture: any + Multi-Arch: <CURSOR> +""" + ) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert keywords == {"no", "same", "foreign", "allowed"} + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + Architecture: all + Multi-Arch: <CURSOR> +""" + ) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert keywords == {"no", "foreign", "allowed"} + def test_dctrl_hover_doc_field(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" |