summaryrefslogtreecommitdiffstats
path: root/tests/python/test_position.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/python/test_position.py49
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"))