|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +import json |
| 5 | +import uuid |
| 6 | + |
| 7 | +import hamcrest |
| 8 | +import jsonrpc |
| 9 | +import pytest |
| 10 | +from cattrs.errors import ClassValidationError |
| 11 | + |
| 12 | +ID = str(uuid.uuid4()) |
| 13 | + |
| 14 | +TEST_DATA = [ |
| 15 | + ( |
| 16 | + { |
| 17 | + "id": ID, |
| 18 | + "method": "inlayHint/resolve", |
| 19 | + "params": { |
| 20 | + "position": {"line": 6, "character": 5}, |
| 21 | + "label": "a label", |
| 22 | + "kind": 1, |
| 23 | + "paddingLeft": False, |
| 24 | + "paddingRight": True, |
| 25 | + }, |
| 26 | + "jsonrpc": "2.0", |
| 27 | + }, |
| 28 | + json.dumps( |
| 29 | + { |
| 30 | + "id": ID, |
| 31 | + "params": { |
| 32 | + "position": {"line": 6, "character": 5}, |
| 33 | + "label": "a label", |
| 34 | + "kind": 1, |
| 35 | + "paddingLeft": False, |
| 36 | + "paddingRight": True, |
| 37 | + }, |
| 38 | + "method": "inlayHint/resolve", |
| 39 | + "jsonrpc": "2.0", |
| 40 | + } |
| 41 | + ), |
| 42 | + ), |
| 43 | + ( |
| 44 | + { |
| 45 | + "id": ID, |
| 46 | + "method": "inlayHint/resolve", |
| 47 | + "params": { |
| 48 | + "position": {"line": 6, "character": 5}, |
| 49 | + "label": [ |
| 50 | + {"value": "part 1"}, |
| 51 | + {"value": "part 2", "tooltip": "a tooltip"}, |
| 52 | + ], |
| 53 | + "kind": 1, |
| 54 | + "paddingLeft": False, |
| 55 | + "paddingRight": True, |
| 56 | + }, |
| 57 | + "jsonrpc": "2.0", |
| 58 | + }, |
| 59 | + json.dumps( |
| 60 | + { |
| 61 | + "id": ID, |
| 62 | + "params": { |
| 63 | + "position": {"line": 6, "character": 5}, |
| 64 | + "label": [ |
| 65 | + {"value": "part 1"}, |
| 66 | + {"value": "part 2", "tooltip": "a tooltip"}, |
| 67 | + ], |
| 68 | + "kind": 1, |
| 69 | + "paddingLeft": False, |
| 70 | + "paddingRight": True, |
| 71 | + }, |
| 72 | + "method": "inlayHint/resolve", |
| 73 | + "jsonrpc": "2.0", |
| 74 | + } |
| 75 | + ), |
| 76 | + ), |
| 77 | +] |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.parametrize("index", list(range(0, len(TEST_DATA)))) |
| 81 | +def test_inlay_hint_resolve_request_serialization(index): |
| 82 | + data, expected = TEST_DATA[index] |
| 83 | + data_str = json.dumps(data) |
| 84 | + parsed = jsonrpc.from_json(data_str) |
| 85 | + actual_str = jsonrpc.to_json(parsed) |
| 86 | + hamcrest.assert_that(actual_str, hamcrest.is_(expected)) |
0 commit comments