Пример #1
0
def test_get_last_line_col():
    d = Document(uri="", source="")
    assert d.get_last_line_col() == (0, 0)
    d.source = "my"
    assert d.get_last_line_col() == (0, 2)
    d.source = "my\n"
    assert d.get_last_line_col() == (1, 0)
Пример #2
0
def test_get_line():
    d = Document(uri="", source="")
    assert d.get_last_line() == ""
    d.source = "my\nfoo"
    assert d.get_line(0) == "my"
    assert d.get_last_line() == "foo"
    assert d.get_line_count() == 2

    d.source = "my\nfoo\n"
    assert d.get_line(0) == "my"
    assert d.get_line(1) == "foo"
    assert d.get_line(2) == ""
    assert d.get_last_line() == ""

    assert list(d.iter_lines()) == ["my\n", "foo\n", ""]
    assert list(d.iter_lines(False)) == ["my", "foo", ""]
def test_robotframework_integrated_completions(rf_configured_api, rf_root):
    from robocorp_ls_core import uris
    from robocorp_ls_core.workspace import Document

    api = rf_configured_api

    doc_uri = uris.from_fs_path(
        str(rf_root / "atest" / "robot" / "cli" / "dryrun" / "args.robot"))
    text = """*** Settings ***
Suite Setup      Run Tests    --dryrun    cli/dryrun/args.robot
Resource         atest_resource.robot

*** Test Cases ***
Valid positional args
    Check Test Case    ${TESTNAME}

Too few arguments
    Check Test Case    ${TESTNAME}

Too few arguments for UK
    Check Test Case    ${TESTNAME}

Too many arguments
    Check Test Case    ${TESTNAME}

Valid named args
    Check Test Case    ${TESTNAME}

Invalid named args
    Check Test Case    ${TESTNAME}
    Ch"""

    api.m_text_document__did_open(textDocument={"uri": doc_uri, "text": text})
    api.workspace.wait_for_check_done(10)
    doc = Document("")
    doc.source = text

    PRINT_TIMES = False
    if PRINT_TIMES:
        import time

        curtime = time.time()

    for i in range(5):
        line, col = doc.get_last_line_col()
        func = api.m_complete_all(doc_uri, line, col)
        assert len(func(monitor=NULL)) > 10
        if PRINT_TIMES:
            print("Total %s: %.2fs" % (i, time.time() - curtime))
            curtime = time.time()
def test_robotframework_integrated_go_to_def(rf_configured_api, rf_root):
    from robocorp_ls_core import uris
    from robocorp_ls_core.workspace import Document

    api = rf_configured_api

    doc_uri = uris.from_fs_path(
        str(rf_root / "atest" / "resources" / "foobar.robot"))
    text = """*** Settings ***
Library           TestCheckerLibrary"""

    api.m_text_document__did_open(textDocument={"uri": doc_uri, "text": text})
    doc = Document("")
    doc.source = text

    line, col = doc.get_last_line_col()
    func = api.m_find_definition(doc_uri, line, col)
    found = func(monitor=NULL)
    assert len(found) == 1
    found[0]["uri"].endswith("TestCheckerLibrary.py")