From 8be448d3881909fb0ce4b033cad71aa7575de0aa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:55:48 +0200 Subject: Adding upstream version 2023.0.0. Signed-off-by: Daniel Baumann --- tests/python/test_position.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/python/test_position.py (limited to 'tests/python/test_position.py') 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")) -- cgit v1.2.3