Esempio n. 1
0
def test_run_error_correct_end_column(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri=".my.uri.", text="a = 1\nb=car")
    d.run(ws, doc)
    endpoint.notify.assert_called_with(
        "textDocument/publishDiagnostics",
        {
            "uri":
            doc.uri,
            "diagnostics": [{
                "range": {
                    "start": {
                        "line": 1,
                        "character": 2
                    },
                    "end": {
                        "line": 1,
                        "character": 5
                    },
                },
                "message": "E0101: Variable `car` has not been defined.",
                "severity": DiagnosticSeverity.Error,
            }],
        },
    )
Esempio n. 2
0
def test_run_error(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri='.my.uri.', text='a = foo')
    d.run(ws, doc)
    endpoint.notify.assert_called_with(
        'textDocument/publishDiagnostics', {
            'uri':
            doc.uri,
            'diagnostics': [{
                'range': {
                    'start': {
                        'line': 1,
                        'character': 5
                    },
                    'end': {
                        'line': 1,
                        'character': 8
                    },
                },
                'message': 'E0101: Variable `foo` has not been defined.',
                'severity': DiagnosticSeverity.Error
            }]
        })
Esempio n. 3
0
def test_run_error_correct_column(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri=".my.uri.", text="a = 1\nb=$")
    d.run(ws, doc)
    endpoint.notify.assert_called_with(
        "textDocument/publishDiagnostics",
        {
            "uri":
            doc.uri,
            "diagnostics": [{
                "range": {
                    "start": {
                        "line": 1,
                        "character": 2
                    },
                    "end": {
                        "line": 1,
                        "character": 3
                    },
                },
                "message": "E0041: `$` is not allowed here",
                "severity": DiagnosticSeverity.Error,
            }],
        },
    )
Esempio n. 4
0
def test_run_error_issue_192(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(
        uri=".my.uri.",
        text=
        'when zoom events RecordingCompleted as recording\n  transcript=""',
    )
    d.run(ws, doc)
    endpoint.notify.assert_called_with(
        "textDocument/publishDiagnostics",
        {
            "uri":
            doc.uri,
            "diagnostics": [{
                "range": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 0,
                        "character": 47
                    },
                },
                "message": "E0139: Service `zoom` does not exist on the hub.",
                "severity": DiagnosticSeverity.Error,
            }],
        },
    )
Esempio n. 5
0
def test_run_error_correct_no_column(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri=".my.uri.", text='function foo\n  a = 1\nb="{foo()}"')
    d.run(ws, doc)
    endpoint.notify.assert_called_with(
        "textDocument/publishDiagnostics",
        {
            "uri":
            doc.uri,
            "diagnostics": [{
                "range": {
                    "start": {
                        "line": 2,
                        "character": 0
                    },
                    "end": {
                        "line": 2,
                        "character": 10
                    },
                },
                "message":
                "E0126: Type casting not supported from `none` to `string`.",
                "severity": DiagnosticSeverity.Error,
            }],
        },
    )
Esempio n. 6
0
def test_run_no_error(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri='.my.uri.', text='a = 0')
    d.run(ws, doc)
    endpoint.notify.assert_called_with('textDocument/publishDiagnostics', {
        'uri': doc.uri,
        'diagnostics': [],
    })
Esempio n. 7
0
def test_run_no_error(magic):
    endpoint = magic()
    d = Diagnostics(endpoint=endpoint)
    ws = magic()
    doc = Document(uri=".my.uri.", text="a = 0")
    d.run(ws, doc)
    endpoint.notify.assert_called_with("textDocument/publishDiagnostics", {
        "uri": doc.uri,
        "diagnostics": [],
    })
Esempio n. 8
0
def test_run_empty(magic, patch):
    endpoint = magic()
    patch.object(Diagnostics, "to_error")
    patch.object(Api, "loads")
    Api.loads.errors.return_value = []
    d = Diagnostics(endpoint=endpoint)
    doc = Document(uri=".my.uri.", text="a = 0")
    d.run(ws=magic(), doc=doc)
    endpoint.notify.assert_called_with("textDocument/publishDiagnostics", {
        "uri": doc.uri,
        "diagnostics": [],
    })
Esempio n. 9
0
def test_run_empty(magic, patch):
    endpoint = magic()
    patch.object(Diagnostics, 'to_error')
    patch.object(Api, 'loads')
    Api.loads.errors.return_value = []
    d = Diagnostics(endpoint=endpoint)
    doc = Document(uri='.my.uri.', text='a = 0')
    d.run(ws=magic(), doc=doc)
    endpoint.notify.assert_called_with('textDocument/publishDiagnostics', {
        'uri': doc.uri,
        'diagnostics': [],
    })
Esempio n. 10
0
def test_to_error_end(magic):
    e = magic()
    e.int_line.return_value = 0
    e.error.column = 10
    e.error.end_column = 42
    d = Diagnostics(endpoint=None)
    assert d.to_error(e) == {
        'range': {
            'start': {'line': 0, 'character': 10},
            'end': {'line': 0, 'character': 42},
        },
        'message': e.short_message(),
        'severity': DiagnosticSeverity.Error
    }
Esempio n. 11
0
def test_run_story_error_internal(magic, patch):
    endpoint = magic()
    se = StoryError(None, None)
    patch.init(Story)
    patch.object(Diagnostics, "to_error")
    patch.object(Api, "loads")
    Api.loads().errors.return_value = [se]
    d = Diagnostics(endpoint=endpoint)
    doc = Document(uri=".my.uri.", text="a = 0")
    d.run(ws=magic(), doc=doc)
    d.to_error.assert_not_called()
    endpoint.notify.assert_called_with("textDocument/publishDiagnostics", {
        "uri": doc.uri,
        "diagnostics": [],
    })
Esempio n. 12
0
def test_run_story_error(magic, patch):
    endpoint = magic()
    se = StoryError(None, None)
    patch.init(Story)
    patch.object(Diagnostics, 'to_error')
    patch.object(Api, 'loads')
    Api.loads().errors.return_value = [se]
    d = Diagnostics(endpoint=endpoint)
    doc = Document(uri='.my.uri.', text='a = 0')
    d.run(ws=magic(), doc=doc)
    d.to_error.assert_called_with(se)
    endpoint.notify.assert_called_with('textDocument/publishDiagnostics', {
        'uri': doc.uri,
        'diagnostics': [Diagnostics.to_error()],
    })
Esempio n. 13
0
def test_to_error_end(magic):
    e = magic()
    e.int_line.return_value = 0
    e.error.column = 10
    e.error.end_column = 42
    d = Diagnostics(endpoint=None)
    assert d.to_error(e) == {
        "range": {
            "start": {
                "line": 0,
                "character": 9
            },
            "end": {
                "line": 0,
                "character": 41
            },
        },
        "message": e.short_message(),
        "severity": DiagnosticSeverity.Error,
    }