Exemplo n.º 1
0
def test_print_ast(data_regression):
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl import ast_utils

    try:
        from StringIO import StringIO
    except ImportError:
        from io import StringIO

    doc = RobotDocument("unused", source="*** settings ***")
    s = StringIO()
    ast_utils.print_ast(doc.get_ast(), stream=s)
    assert [
        x.replace("SETTING HEADER", "SETTING_HEADER")
        for x in s.getvalue().splitlines()
    ] in (
        [
            "  File                                               (0, 0) -> (0, 16)",
            "    SettingSection                                   (0, 0) -> (0, 16)",
            "      SettingSectionHeader                           (0, 0) -> (0, 16)",
            "      - SETTING_HEADER, '*** settings ***'                  (0, 0->16)",
            "      - EOL, ''                                            (0, 16->16)",
        ],
        [  # version 4.0.4 onwards
            "  File                                               (0, 0) -> (0, 16)",
            "    SettingSection                                   (0, 0) -> (0, 16)",
            "      SectionHeader                                  (0, 0) -> (0, 16)",
            "      - SETTING_HEADER, '*** settings ***'                  (0, 0->16)",
            "      - EOL, ''                                            (0, 16->16)",
        ],
    )
Exemplo n.º 2
0
def test_print_ast(data_regression):
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl import ast_utils

    try:
        from StringIO import StringIO
    except ImportError:
        from io import StringIO

    doc = RobotDocument("unused", source="*** settings ***")
    s = StringIO()
    ast_utils.print_ast(doc.get_ast(), stream=s)
    data_regression.check(s.getvalue().splitlines())
Exemplo n.º 3
0
def test_parse_errors_for(data_regression):
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl.ast_utils import collect_errors
    from robotframework_ls.impl import ast_utils

    source = """
*** Test Cases ***
Invalid END
    FOR    ${var}    IN    one    two
        Fail    Not executed
"""

    doc = RobotDocument("unsaved", source)
    ast_utils.print_ast(doc.get_ast())
    errors = collect_errors(doc.get_ast())

    data_regression.check([e.to_dict() for e in errors], basename="errors_for")
Exemplo n.º 4
0
def test_parse_errors_if(data_regression):
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl.ast_utils import collect_errors
    from robotframework_ls.impl import ast_utils

    source = """
*** Test Cases ***
If without end
    IF  ${True}
       No Operation
"""

    doc = RobotDocument("unsaved", source)
    ast_utils.print_ast(doc.get_ast())
    errors = collect_errors(doc.get_ast())

    data_regression.check([e.to_dict() for e in errors], basename="errors_if")
Exemplo n.º 5
0
def check(found, expected):
    from robotframework_ls.impl.semantic_tokens import decode_semantic_tokens
    from robotframework_ls.impl.completion_context import CompletionContext
    from robotframework_ls.impl import ast_utils
    import robot

    semantic_tokens_as_int: List[int] = found[0]
    doc: IDocument = found[1]
    decoded = decode_semantic_tokens(semantic_tokens_as_int, doc)
    if decoded != expected:
        from io import StringIO

        stream = StringIO()
        ast_utils.print_ast(CompletionContext(doc).get_ast(), stream=stream)
        raise AssertionError(
            "Expected:\n%s\n\nFound:\n%s\n\nAst:\n%s\n\nRobot: %s %s" %
            (expected, decoded, stream.getvalue(), robot.get_version(), robot))
Exemplo n.º 6
0
def test_parse_errors(data_regression):
    from robotframework_ls.impl.robot_workspace import RobotDocument
    from robotframework_ls.impl.ast_utils import collect_errors
    from robotframework_ls.impl import ast_utils

    source = """*** Settings ***
Documentation     A test suite with a single test for valid login.
...
...               This test has a workflow that is created using keywords in
...               the imported resource file.
Resource          resource.txt

"test"

*** Invalid Invalid Invalid ***
    Something

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Input Username    demo
    Input Password    mode
    Submit Credentials
    Welcome Page Should Be Open
    [Teardown]    Close Browser"""

    doc = RobotDocument("unsaved", source)
    ast_utils.print_ast(doc.get_ast())
    errors = collect_errors(doc.get_ast())

    data_regression.check([e.to_dict() for e in errors], basename="errors")

    data_regression.check([e.to_lsp_diagnostic() for e in errors],
                          basename="lsp_diagnostic")

    assert repr(errors)  # Just check that it works.