Esempio n. 1
0
def test_formatting_basic(data_regression):
    from robotframework_ls.impl.formatting import (
        robot_source_format,
        create_text_edit_from_diff,
    )
    from robocode_ls_core.workspace import Document

    contents = u"""
***Settings***
[Documentation]Some doc

***Test Case***
Check
    Call  1  2"""
    new_contents = robot_source_format(contents)
    assert u"*** Settings ***" in new_contents

    text_edits = create_text_edit_from_diff(contents, new_contents)

    doc = Document("", contents)
    doc.apply_text_edits(text_edits)
    data_regression.check(doc.source,
                          basename="test_formatting_basic_formatted_doc")
    data_regression.check([x.to_dict() for x in text_edits],
                          basename="test_formatting_basic_text_edits")
Esempio n. 2
0
def test_document_end_of_file_edit():
    old = ["print 'a'\n", "print 'b'\n"]
    doc = Document("file:///uri", u"".join(old))

    change = TextDocumentContentChangeEvent(
        Range(Position(2, 0), Position(2, 0)), 0, u"o")
    doc.apply_change(change)

    assert doc.get_internal_lines() == ("print 'a'\n", "print 'b'\n", "o")
Esempio n. 3
0
def test_document_multiline_edit():
    old = ["def hello(a, b):\n", "    print a\n", "    print b\n"]
    doc = Document("file:///uri", u"".join(old))
    change = TextDocumentContentChangeEvent(
        Range(Position(1, 4), Position(2, 11)), 0, u"print a, b")
    doc.apply_change(change)

    assert doc.get_internal_lines() == ("def hello(a, b):\n",
                                        "    print a, b\n")
Esempio n. 4
0
def test_offset_to_line_col_1():
    d = Document(uri="", source="my\nfo\nba")
    assert d.offset_to_line_col(0) == (0, 0)
    assert d.offset_to_line_col(1) == (0, 1)
    assert d.offset_to_line_col(2) == (0, 2)

    assert d.offset_to_line_col(3) == (1, 0)
    assert d.offset_to_line_col(4) == (1, 1)
    assert d.offset_to_line_col(5) == (1, 2)

    assert d.offset_to_line_col(6) == (2, 0)
    assert d.offset_to_line_col(7) == (2, 1)
    assert d.offset_to_line_col(8) == (2, 2)

    # Note: block below is out of bounds
    assert d.offset_to_line_col(9) == (2, 3)
    assert d.offset_to_line_col(10) == (2, 4)
Esempio n. 5
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)
Esempio n. 6
0
def test_snippets_completions_integrated(language_server_tcp, ws_root_path,
                                         data_regression):
    from robocode_ls_core.workspace import Document

    language_server = language_server_tcp
    language_server.initialize(ws_root_path, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """
*** Test Cases ***
List Variable
    for/"""
    language_server.change_doc(uri, 2, contents)

    doc = Document("", source=contents)
    line, col = doc.get_last_line_col()
    completions = language_server.get_completions(uri, line, col)
    del completions["id"]
    data_regression.check(completions, "snippet_completions")
Esempio n. 7
0
def test_variables_completions_integrated(
        language_server_tcp: ILanguageServerClient, ws_root_path,
        data_regression):
    from robocode_ls_core.workspace import Document

    language_server = language_server_tcp
    language_server.initialize(ws_root_path, process_id=os.getpid())
    uri = "untitled:Untitled-1"
    language_server.open_doc(uri, 1)
    contents = """
*** Variables ***
${NAME}         Robot Framework
${VERSION}      2.0
${ROBOT}        ${NAME} ${VERSION}

*** Test Cases ***
List Variable
    Log    ${NAME}
    Should Contain    ${"""
    language_server.change_doc(uri, 2, contents)

    doc = Document("", source=contents)
    line, col = doc.get_last_line_col()
    completions = language_server.get_completions(uri, line, col)
    del completions["id"]
    data_regression.check(completions, "variable_completions")

    # Note: for libraries, if we found it, we keep it in memory (so, even though
    # we removed the entry, it'll still be accessible).
    language_server_tcp.settings(
        {"settings": {
            "robot": {
                "variables": {
                    "myvar1": 10
                }
            }
        }})

    completions = language_server.get_completions(uri, line, col)
    labels = [x["label"] for x in completions["result"]]
    assert "${myvar1}" in labels
Esempio n. 8
0
def test_offset_to_line_col_2():
    d = Document(uri="", source="\n\n\n")
    with pytest.raises(ValueError):
        assert d.offset_to_line_col(-1)

    assert d.offset_to_line_col(0) == (0, 0)
    assert d.offset_to_line_col(1) == (1, 0)
    assert d.offset_to_line_col(2) == (2, 0)

    # Note: block below is out of bounds
    assert d.offset_to_line_col(3) == (3, 0)
    assert d.offset_to_line_col(4) == (3, 1)
Esempio n. 9
0
 def request_completion():
     doc = Document("", source=contents)
     line, col = doc.get_last_line_col()
     completions = language_server.get_completions(uri, line, col)
     del completions["id"]
     return completions
Esempio n. 10
0
def test_document_source_unicode():
    document_mem = Document(DOC_URI, u"my source")
    document_disk = Document(DOC_URI)
    assert isinstance(document_mem.source, type(document_disk.source))
Esempio n. 11
0
def test_document_line_edit():
    doc = Document("file:///uri", u"itshelloworld")
    change = TextDocumentContentChangeEvent(
        Range(Position(0, 3), Position(0, 8)), 0, u"goodbye")
    doc.apply_change(change)
    assert doc.source == u"itsgoodbyeworld"
Esempio n. 12
0
def test_document_empty_edit():
    doc = Document("file:///uri", u"")
    change = TextDocumentContentChangeEvent(
        Range(Position(0, 0), Position(0, 0)), 0, u"f")
    doc.apply_change(change)
    assert doc.source == u"f"
Esempio n. 13
0
def doc():
    return Document(DOC_URI, DOC)
Esempio n. 14
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", ""]
Esempio n. 15
0
 def _clear_caches(self):
     Document._clear_caches(self)
     self.get_ast.cache_clear(self)
Esempio n. 16
0
 def __init__(self, uri, source=None, version=None, generate_ast=True):
     Document.__init__(self, uri, source=source, version=version)
     self._generate_ast = generate_ast
     self._ast = None