Exemple #1
0
def test_find_definition_same_basename(workspace, libspec_manager, cases,
                                       tmpdir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.find_definition import find_definition

    workspace.set_root("case_same_basename", libspec_manager=libspec_manager)
    doc1 = workspace.get_doc("tasks1.robot")
    doc2 = workspace.get_doc("directory/tasks2.robot")

    completion_context = CompletionContext(doc1, workspace=workspace.ws)
    def1 = find_definition(completion_context)

    completion_context = CompletionContext(doc2, workspace=workspace.ws)
    def2 = find_definition(completion_context)
    assert len(def1) == 1
    assert len(def2) == 1
    assert (def1[0].source.replace(
        "\\", "/").endswith("case_same_basename/my_library.py"))
    assert (def2[0].source.replace(
        "\\", "/").endswith("case_same_basename/directory/my_library.py"))

    found = [
        lib_info for lib_info in libspec_manager.iter_lib_info()
        if lib_info.library_doc.name == "my_library"
    ]

    assert len(found) == 2
def test_section_completions(data_regression):
    from robotframework_ls.impl import section_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.config.config import Config

    config = Config(root_uri="", init_opts={}, process_id=-1, capabilities={})
    config.update(
        {"robot": {
            "completions": {
                "section_headers": {
                    "form": "both"
                }
            }
        }})

    doc = RobotDocument("unused", source="""**""")
    completions = section_completions.complete(
        CompletionContext(doc, config=config))
    data_regression.check(completions, basename="header_completions_all")

    doc = RobotDocument("unused", source="""**settin""")
    completions = section_completions.complete(
        CompletionContext(doc, config=config))
    data_regression.check(completions,
                          basename="header_completions_filter_settings")

    config.update({})
    doc = RobotDocument("unused", source="""**""")
    completions = section_completions.complete(
        CompletionContext(doc, config=config))
    data_regression.check(completions,
                          basename="header_completions_all_plural")
Exemple #3
0
def test_completion_with_auto_import_resource_import(workspace,
                                                     setup_case2_in_dir_doc):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import auto_import_completions
    from robocorp_ls_core.basic import wait_for_condition

    doc = workspace.get_doc("case1.robot")

    doc.source = """
*** Keywords ***
KeywordInCase1
    In Lib 2
"""

    doc2 = setup_case2_in_dir_doc
    doc2.source = """
*** Test Cases ***
User can call library
    KeywordInCa"""

    wait_for_condition(lambda: len(
        auto_import_completions.complete(
            CompletionContext(doc2, workspace=workspace.ws), {})) == 1)
    completions = auto_import_completions.complete(
        CompletionContext(doc2, workspace=workspace.ws), {})

    assert len(completions) == 1
    apply_completion(doc2, completions[0])

    assert (doc2.source == """*** Settings ***
Resource    ../case1.robot

*** Test Cases ***
User can call library
    KeywordInCase1""")
def test_keyword_completions_library_prefix(
    workspace, libspec_manager, data_regression
):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")

    doc.source = """*** Settings ***
Library    String
Library    Collections
Resource    case4resource.txt

*** Test Cases ***
Test
    case4resource3."""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws)
    )

    data_regression.check(
        completions, basename="test_keyword_completions_library_prefix_1"
    )

    doc.source = """*** Settings ***
Library    String
Library    Collections
Resource    case4resource.txt

*** Test Cases ***
Test
    case4resource3.Another"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws)
    )

    data_regression.check(
        completions, basename="test_keyword_completions_library_prefix_2"
    )

    doc.source = """*** Settings ***
Library    Collections

*** Test Cases ***
Test
    Collections.Append To Lis"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws)
    )
    assert [completion["label"] for completion in completions] == ["Append To List"]
def test_completion_with_auto_import_duplicated(workspace,
                                                setup_case2_in_dir_doc):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import auto_import_completions
    from robotframework_ls.impl.protocols import IKeywordFound
    from robotframework_ls.impl.collect_keywords import (
        collect_keyword_name_to_keyword_found, )
    from robocorp_ls_core.lsp import TextDocumentItem

    doc = workspace.get_doc("case1.robot")

    doc.source = """
*** Keywords ***
KeywordInCase1
    In Lib 2
"""

    # Just create a dummy entry for KeywordInCase1.
    doc_foobar = workspace.ws.put_document(
        TextDocumentItem(
            "foobar",
            text="""
*** Keywords ***
KeywordInCase1
    In Lib 2
""",
        ))

    keyword_name_to_keyword_found: Dict[
        str, List[IKeywordFound]] = collect_keyword_name_to_keyword_found(
            CompletionContext(doc_foobar, workspace=workspace.ws))

    doc2 = setup_case2_in_dir_doc
    doc2.source = """
*** Test Cases ***
User can call library
    KeywordInCa"""

    completions = auto_import_completions.complete(
        CompletionContext(doc2, workspace=workspace.ws),
        keyword_name_to_keyword_found)

    assert len(completions) == 1
    apply_completion(doc2, completions[0])

    assert (doc2.source == """*** Settings ***
Resource    ../case1.robot

*** Test Cases ***
User can call library
    case1.KeywordInCase1""")
    def threaded_monaco_completions_from_code_full(
        self,
        prefix: str,
        full_code: str,
        position: PositionTypedDict,
        uri: str,
        indent: str,
        monitor: Optional[IMonitor] = None,
    ):
        from robotframework_ls.impl.robot_workspace import RobotDocument
        from robotframework_ls.impl.completion_context import CompletionContext
        from robocorp_ls_core.workspace import Document
        from robotframework_ls.impl import section_completions
        from robotframework_ls.impl import snippets_completions
        from robotframework_ls.server_api.monaco_conversions import (
            convert_to_monaco_completion,
        )
        from robotframework_ls.impl.completion_context import CompletionType

        d = Document(uri, prefix)
        last_line, _last_col = d.get_last_line_col()
        line = last_line + position["line"]

        col = position["character"]
        col += len(indent)

        document = RobotDocument(uri, full_code)
        completion_context = CompletionContext(
            document,
            line,
            col,
            config=self.config,
            monitor=monitor,
            workspace=self.workspace,
        )
        completion_context.type = CompletionType.shell
        completions = self._complete_from_completion_context(completion_context)
        completions.extend(section_completions.complete(completion_context))
        completions.extend(snippets_completions.complete(completion_context))

        return {
            "suggestions": [
                convert_to_monaco_completion(
                    c, line_delta=last_line, col_delta=len(indent), uri=uri
                )
                for c in completions
            ]
        }
Exemple #7
0
def test_keyword_completions_resource_does_not_exist(workspace,
                                                     libspec_manager,
                                                     data_regression):
    from robotframework_ls.robot_config import RobotConfig
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")

    doc.source = """*** Settings ***
Library    DoesNotExist
Library    .
Library    ..
Library    ../
Resource    does_not_exist.txt
Resource    ${foo}/does_not_exist.txt
Resource    ../does_not_exist.txt
Resource    .
Resource    ..
Resource    ../
Resource    ../../does_not_exist.txt
Resource    case4resource.txt

*** Test Cases ***
Test
    case4resource3."""

    config = RobotConfig()
    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))

    data_regression.check(completions)
Exemple #8
0
def test_keyword_completions_format(workspace, libspec_manager):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.robot_config import RobotConfig
    from robotframework_ls.impl.robot_lsp_constants import (
        OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT,
        OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT_FIRST_UPPER,
    )

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = doc.source + "\n    should be"

    config = RobotConfig()
    config.update({
        OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT:
        OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT_FIRST_UPPER
    })
    assert (config.get_setting(
        OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT, str,
        "") == OPTION_ROBOT_COMPLETION_KEYWORDS_FORMAT_FIRST_UPPER)

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))
    assert sorted([comp["label"] for comp in completions]) == [
        "Length should be",
        "Should be empty",
        "Should be equal",
        "Should be equal as integers",
        "Should be equal as numbers",
        "Should be equal as strings",
        "Should be true",
    ]
Exemple #9
0
def test_keyword_completions_from_resource_files(data_regression, workspace,
                                                 tmpdir, cases,
                                                 libspec_manager):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_VARIABLES
    from robotframework_ls.robot_config import RobotConfig

    config = RobotConfig()
    config.update(
        {"robot": {
            "variables": {
                "ext_folder": cases.get_path("ext")
            }
        }})
    assert config.get_setting(OPTION_ROBOT_VARIABLES, dict, {}) == {
        "ext_folder": cases.get_path("ext")
    }

    workspace.set_root(cases.get_path("case3"),
                       libspec_manager=libspec_manager)
    doc = workspace.get_doc("case3.robot")
    doc.source = doc.source + "\n    equal redef"

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))
    data_regression.check(completions,
                          basename="keyword_completions_from_resource_files")
Exemple #10
0
def test_completion_with_auto_import_case1_library_imported_3(
        workspace, setup_case2_in_dir_doc):
    from robotframework_ls.impl import auto_import_completions
    from robotframework_ls.impl.completion_context import CompletionContext

    doc = setup_case2_in_dir_doc

    # Get completions from the user library adding the existing *** Settings ***
    doc.source = """*** Settings ***

*** Test Cases ***
User can call library
    Verify another m"""

    # Needed to pre-generate the information
    workspace.ws.libspec_manager.get_library_info(
        libname="case1_library",
        create=True,
        current_doc_uri=workspace.get_doc("case1.robot").uri,
    )

    completions = auto_import_completions.complete(
        CompletionContext(doc, workspace=workspace.ws), {})

    assert len(completions) == 1
    apply_completion(doc, completions[0])

    assert (doc.source == """*** Settings ***
Library    ../case1_library.py

*** Test Cases ***
User can call library
    Verify Another Model""")
Exemple #11
0
def test_keyword_completions_builtin_after_space_before_newline(
        workspace, libspec_manager):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = doc.source + "\n    should be \n"

    line, _col = doc.get_last_line_col()
    line_contents = doc.get_line(line - 1)

    completions = keyword_completions.complete(
        CompletionContext(doc,
                          workspace=workspace.ws,
                          line=line - 1,
                          col=len(line_contents)))

    assert sorted([comp["label"] for comp in completions]) == [
        "Length Should Be",
        "Should Be Empty",
        "Should Be Equal",
        "Should Be Equal As Integers",
        "Should Be Equal As Numbers",
        "Should Be Equal As Strings",
        "Should Be True",
    ]
Exemple #12
0
def test_keyword_completions_directory_separator(workspace, libspec_manager,
                                                 use_config, separator):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.robot_config import RobotConfig
    import sys

    if sys.platform != "win32" and separator == "\\":
        return

    workspace.set_root("case_inner_keywords", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case_root.robot")
    doc.source = f"""
*** Settings ***
Resource    inner{separator}case_inner.robot


*** Test Cases ***
Testing Completion Here
    Check with ke"""

    if use_config:
        config = RobotConfig()
    else:
        config = None

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))
    assert sorted([comp["label"] for comp in completions
                   ]) == ["Check with keyword at inner"]
def test_resource_completions_resolve_var(data_regression, workspace, cases,
                                          libspec_manager, workspace_dir):
    from robotframework_ls.impl import filesystem_section_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_VARIABLES
    from robotframework_ls.robot_config import RobotConfig

    cases.copy_to("case4", workspace_dir)

    config = RobotConfig()
    config.update(
        {"robot": {
            "variables": {
                "ext_folder": cases.get_path("ext")
            }
        }})
    assert config.get_setting(OPTION_ROBOT_VARIABLES, dict, {}) == {
        "ext_folder": cases.get_path("ext")
    }

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """*** Settings ***
Resource           ${ext_folder}/"""

    completions = filesystem_section_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))

    data_regression.check(completions)
Exemple #14
0
def test_find_definition_keyword_resource_in_pythonpath(
        workspace, libspec_manager, cases):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.find_definition import find_definition
    from robotframework_ls.robot_config import RobotConfig
    from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_PYTHONPATH

    case2_path = cases.get_path("case2")
    config = RobotConfig()
    config.update({"robot": {"pythonpath": [case2_path]}})
    assert config.get_setting(OPTION_ROBOT_PYTHONPATH, list,
                              []) == [case2_path]
    libspec_manager.config = config

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Settings ***
Resource    case2.robot"""

    completion_context = CompletionContext(doc,
                                           workspace=workspace.ws,
                                           config=config)
    definitions = find_definition(completion_context)
    assert len(definitions) == 1, "Failed to find definition"
    definition = next(iter(definitions))
    assert definition.source.endswith("case2.robot")
    assert definition.lineno == 0
Exemple #15
0
def test_find_definition_should_not_resolve_link_in_resource(
        workspace, libspec_manager, cases, tmpdir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.find_definition import find_definition

    target_original, target_link = create_case_as_link(cases, tmpdir, "case4")
    workspace.set_absolute_path_root(target_link,
                                     libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """*** Settings ***
Library    String
Library    Collections
Resource    case4resource.txt

*** Test Cases ***
Test
    case4resource3.Yet Another Equal Redefined"""

    completion_context = CompletionContext(doc, workspace=workspace.ws)
    definitions = find_definition(completion_context)
    assert len(definitions) == 1
    definition = next(iter(definitions))
    assert definition.source.endswith("case4resource3.robot")
    assert definition.lineno == 1
    check_using_link_version(definition.source, target_link, target_original)
Exemple #16
0
def test_folding_range_basic(workspace, libspec_manager, data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.folding_range import folding_range

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source += """
*** Test Cases ***
Log It
    Log   
    Log   
    
Log It 2
    Log   
    Log   
Log It 3
    Log   
    Log 
    FOR    ${element}    IN    @{LIST}
        Log    ${element}
        
    END
Nothing here  
"""

    completion_context = CompletionContext(doc, workspace=workspace.ws)

    data_regression.check(folding_range(completion_context))
Exemple #17
0
def test_string_variables_completions_unable_to_tokenize_2(
        workspace, libspec_manager, data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import variable_completions

    workspace.set_root("case1", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Variables ***
${NAME}         Robot Framework
${VERSION}      2.0
${ROBOT} =      ${NAME} ${VERSION}

*** Test Cases ***
List Variable
    Log    ${NAME}
    Should Contain    ${na ${na}"""

    line, col = doc.get_last_line_col()
    completions = variable_completions.complete(
        CompletionContext(doc,
                          workspace=workspace.ws,
                          line=line,
                          col=col - len(" ${na}")))
    data_regression.check(completions)
Exemple #18
0
def test_completion_with_auto_import_import_not_duplicated_case1_library(
        workspace, cases, libspec_manager, workspace_dir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import auto_import_completions

    cases.copy_to("case1", workspace_dir)

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")

    doc.source = """
*** Settings ***
Library    case1_library

*** Test Cases ***
User can call library
    Verify another m"""

    # Needed to pre-generate the information
    workspace.ws.libspec_manager.get_library_info(
        libname="case1_library",
        create=True,
        current_doc_uri=workspace.get_doc("case1.robot").uri,
    )

    completions = auto_import_completions.complete(
        CompletionContext(doc, workspace=workspace.ws), {})

    assert len(completions) == 0
def test_complete_from_context(rf_server_api, libspec_manager, tmpdir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl.robot_workspace import RobotWorkspace
    from robocorp_ls_core.watchdog_wrapper import create_observer

    api = rf_server_api

    text = """*** Task ***
Some task
    Log    Something     console=True
    Lo"""

    doc = RobotDocument("", text)

    line, col = doc.get_last_line_col()
    workspace = RobotWorkspace(
        str(tmpdir),
        fs_observer=create_observer("dummy", []),
        libspec_manager=libspec_manager,
    )
    completion_context = CompletionContext(doc, line, col, workspace=workspace)

    for completion in api._complete_from_completion_context(completion_context):
        if completion["label"] == "Log":
            break
    else:
        raise AssertionError('Did not find "Log" entry in completions.')
Exemple #20
0
def test_completion_with_auto_import_import_not_duplicated_stdlib(
        workspace, cases, libspec_manager, workspace_dir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import auto_import_completions

    cases.copy_to("case1", workspace_dir)

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")

    doc.source = """
*** Settings ***
Library    case1_library.py
Library    Collections

*** Test Cases ***
User can call library
    Copy Diction"""

    completions = auto_import_completions.complete(
        CompletionContext(doc, workspace=workspace.ws), {})

    # As the Collections library is already there, don't show that completion here
    # (it's already managed in other completions).
    assert len(completions) == 0
Exemple #21
0
def test_keyword_completions_respect_pythonpath(workspace, cases,
                                                libspec_manager,
                                                data_regression):
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.robot_config import RobotConfig
    from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_PYTHONPATH

    case4_path = cases.get_path("case4")

    # Note how we are accessing case4resource.txt while the workspace is set for case3.

    config = RobotConfig()
    config.update({"robot": {"pythonpath": [case4_path]}})
    assert config.get_setting(OPTION_ROBOT_PYTHONPATH, list,
                              []) == [case4_path]
    libspec_manager.config = config

    workspace.set_root(cases.get_path("case3"),
                       libspec_manager=libspec_manager)
    doc = workspace.get_doc("case3.robot")
    doc.source = """*** Settings ***
Resource    case4resource.txt

*** Test Cases ***
Can use resource keywords
    [Documentation]      Checks that we can have a resource
    ...                  including another resource.
    My Equal Redefined   2   2
    Yet Another Equ"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws, config=config))

    data_regression.check(completions)
Exemple #22
0
    def _create_completion_context(
        self, doc_uri, line, col, monitor: Optional[IMonitor]
    ):
        from robotframework_ls.impl.completion_context import CompletionContext

        if not self._check_min_version((3, 2)):
            log.info("robotframework version too old.")
            return None
        workspace = self.workspace
        if not workspace:
            log.info("Workspace still not initialized.")
            return None

        document = workspace.get_document(doc_uri, accept_from_file=True)
        if document is None:
            log.info("Unable to get document for uri: %s.", doc_uri)
            return None
        return CompletionContext(
            document,
            line,
            col,
            workspace=workspace,
            config=self.config,
            monitor=monitor,
        )
Exemple #23
0
def test_typing_not_shown(libspec_manager, workspace, data_regression,
                          workspace_dir):
    from robocorp_ls_core import uris
    from os.path import os
    from robotframework_ls_tests.fixtures import LIBSPEC_3
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    from robocorp_ls_core.lsp import TextDocumentItem

    workspace_dir_a = os.path.join(workspace_dir, "workspace_dir_a")
    os.makedirs(workspace_dir_a)
    with open(os.path.join(workspace_dir_a, "my.libspec"), "w") as stream:
        stream.write(LIBSPEC_3)
    libspec_manager.add_workspace_folder(uris.from_fs_path(workspace_dir_a))
    assert libspec_manager.get_library_info("case3_library",
                                            create=False) is not None

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)

    doc = workspace.ws.put_document(TextDocumentItem("temp_doc.robot",
                                                     text=""))
    doc.source = """*** Settings ***
Library    case3_library

*** Test Cases ***
Can use resource keywords
    Case Verify"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))

    data_regression.check(completions)
Exemple #24
0
def test_semantic_highlighting_arguments(workspace):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.semantic_tokens import semantic_tokens_full

    workspace.set_root("case1")
    doc = workspace.get_doc("case1.robot")
    doc.source = """
*** Test Cases ***
Some Test
    Clear All Highlights    formatter=some ${arg1} other
""".replace("\r\n", "\n").replace("\r", "\n")
    context = CompletionContext(doc, workspace=workspace.ws)
    semantic_tokens = semantic_tokens_full(context)
    check(
        (semantic_tokens, doc),
        [
            ("*** Test Cases ***", "header"),
            ("Some Test", "testCaseName"),
            ("Clear All Highlights", "keywordNameCall"),
            ("formatter", "parameterName"),
            ("=", "variableOperator"),
            ("some ", "argumentValue"),
            ("${", "variableOperator"),
            ("arg1", "variable"),
            ("}", "variableOperator"),
            (" other", "argumentValue"),
        ],
    )
Exemple #25
0
def test_code_lens_run_basic(workspace, libspec_manager, data_regression):
    from robotframework_ls_tests.fixtures import check_code_lens_data_regression
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.code_lens import code_lens_runs
    from robotframework_ls.impl.code_lens import code_lens_resolve

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """

*** Test Cases ***
Some Test
    [Documentation]      Docs
    
*** Task ***
Some Task
    [Documentation]      Docs
"""

    completion_context = CompletionContext(doc, workspace=workspace.ws)

    found = code_lens_runs(completion_context)
    check_code_lens_data_regression(data_regression, found)
    for c in found:
        # i.e.: don't change anything here
        assert code_lens_resolve(completion_context, c) == c
def test_find_definition_variables_dict(workspace, libspec_manager,
                                        data_regression):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.find_definition import find_definition

    workspace.set_root("case4", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case4.robot")
    doc.source = """
*** Variables ***
@{SOME LIST}    foo    bar    baz
&{SOME DICT}    string=cat    int=${1}    list=@{SOME LIST}


*** Test Cases ***
Log Global Constants
    Log    ${SOME LIST}    info
    Log    ${SOME DICT}    info"""

    line, col = doc.get_last_line_col()
    col -= len("CT}    info")
    completion_context = CompletionContext(doc,
                                           workspace=workspace.ws,
                                           line=line,
                                           col=col)
    data_regression.check(
        _definitions_to_data_regression(find_definition(completion_context)))
def test_library_completions_in_dirs(data_regression, workspace, cases,
                                     libspec_manager, workspace_dir):
    from robotframework_ls.impl import filesystem_section_completions
    from robotframework_ls.impl.completion_context import CompletionContext
    import os.path

    cases.copy_to("case1", workspace_dir)

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")
    doc.source = """*** Settings ***
Library           dir1/caseXXX"""

    dir1 = os.path.join(workspace_dir, "dir1")
    os.mkdir(dir1)

    mycase_py = os.path.join(dir1, "mycase.py")
    with open(mycase_py, "w") as stream:
        stream.write("""def my_method():\n    pass""")

    line, col = doc.get_last_line_col()
    completions = filesystem_section_completions.complete(
        CompletionContext(doc,
                          workspace=workspace.ws,
                          line=line,
                          col=col - len("XXX")))

    data_regression.check(completions)
Exemple #28
0
def test_completion_with_auto_import_basic_stdlib(workspace, cases,
                                                  libspec_manager,
                                                  workspace_dir):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import auto_import_completions

    cases.copy_to("case1", workspace_dir)

    workspace.set_root(workspace_dir, libspec_manager=libspec_manager)
    doc = workspace.get_doc("case1.robot")

    doc.source = """
*** Settings ***
Library    case1_library

*** Test Cases ***
User can call library
    Copy Diction"""

    completions = auto_import_completions.complete(
        CompletionContext(doc, workspace=workspace.ws), {})

    assert len(completions) == 1
    apply_completion(doc, completions[0])

    assert (doc.source == """
*** Settings ***
Library    case1_library
Library    Collections

*** Test Cases ***
User can call library
    Copy Dictionary""")
def test_keyword_completions_template(workspace, libspec_manager):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import keyword_completions

    workspace.set_root("case2", libspec_manager=libspec_manager)
    doc = workspace.get_doc("case2.robot")
    doc.source = """
*** Keywords ***
My Equal Redefined
    [Arguments]         ${arg1}     ${arg2}
    Should Be Equal     ${arg1}     ${arg2}

*** Settings ***
Test Template    my eq"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws)
    )

    found = [
        completion["label"]
        for completion in completions
        if completion["label"].lower() == "my equal redefined"
    ]

    assert len(found) == 1
Exemple #30
0
def test_semantic_highlighting_keyword(workspace):
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl.semantic_tokens import semantic_tokens_full

    workspace.set_root("case1")
    doc = workspace.get_doc("case1.robot")
    doc.source = """*** Keywords ***
Some Keyword
    [Arguments]     ${arg1}
    Call Keyword    ${arg1}
""".replace("\r\n", "\n").replace("\r", "\n")
    context = CompletionContext(doc, workspace=workspace.ws)
    semantic_tokens = semantic_tokens_full(context)
    check(
        (semantic_tokens, doc),
        [
            ("*** Keywords ***", "header"),
            ("Some Keyword", "keywordNameDefinition"),
            ("[", "variableOperator"),
            ("Arguments", "setting"),
            ("]", "variableOperator"),
            ("${", "variableOperator"),
            ("arg1", "variable"),
            ("}", "variableOperator"),
            ("Call Keyword", "keywordNameCall"),
            ("${", "variableOperator"),
            ("arg1", "variable"),
            ("}", "variableOperator"),
        ],
    )