summaryrefslogtreecommitdiffstats
path: root/tests/python/test_position.py
blob: 67bff8b9fc6b12c7f7495d4f5f9d88ffc044bcbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import hamcrest
import pytest

from lsprotocol import types as lsp


@pytest.mark.parametrize(
    ("a", "b", "comp", "expected"),
    [
        (lsp.Position(1, 10), lsp.Position(1, 10), "==", True),
        (lsp.Position(1, 10), lsp.Position(1, 11), "==", False),
        (lsp.Position(1, 10), lsp.Position(1, 11), "!=", True),
        (lsp.Position(1, 10), lsp.Position(2, 20), "!=", True),
        (lsp.Position(2, 10), lsp.Position(1, 10), ">", True),
        (lsp.Position(2, 10), lsp.Position(1, 10), ">=", True),
        (lsp.Position(1, 11), lsp.Position(1, 10), ">", True),
        (lsp.Position(1, 11), lsp.Position(1, 10), ">=", True),
        (lsp.Position(1, 10), lsp.Position(1, 10), ">=", True),
        (lsp.Position(1, 10), lsp.Position(2, 10), "<", True),
        (lsp.Position(1, 10), lsp.Position(2, 10), "<=", True),
        (lsp.Position(1, 10), lsp.Position(1, 10), "<=", True),
        (lsp.Position(1, 10), lsp.Position(1, 11), "<", True),
        (lsp.Position(1, 10), lsp.Position(1, 11), "<=", True),
    ],
)
def test_position_comparison(
    a: lsp.Position, b: lsp.Position, comp: str, expected: bool
):
    if comp == "==":
        result = a == b
    elif comp == "!=":
        result = a != b
    elif comp == "<":
        result = a < b
    elif comp == "<=":
        result = a <= b
    elif comp == ">":
        result = a > b
    elif comp == ">=":
        result = a >= b
    hamcrest.assert_that(result, hamcrest.is_(expected))


def test_position_repr():
    p = lsp.Position(1, 23)
    hamcrest.assert_that(f"{p!r}", hamcrest.is_("1:23"))