diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:55:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:55:48 +0000 |
commit | 8be448d3881909fb0ce4b033cad71aa7575de0aa (patch) | |
tree | da33caff06645347a08c3c9c56dd703e4acb5aa3 /tests/python/test_position.py | |
parent | Initial commit. (diff) | |
download | lsprotocol-8be448d3881909fb0ce4b033cad71aa7575de0aa.tar.xz lsprotocol-8be448d3881909fb0ce4b033cad71aa7575de0aa.zip |
Adding upstream version 2023.0.0.upstream/2023.0.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/python/test_position.py')
-rw-r--r-- | tests/python/test_position.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/python/test_position.py b/tests/python/test_position.py new file mode 100644 index 0000000..67bff8b --- /dev/null +++ b/tests/python/test_position.py @@ -0,0 +1,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")) |