[docs] 1# @Test suite for needextend RST generation from extracted markers, TEST_WRITE_1, test, [IMPL_CLI_WRITE]
 2import pytest
 3
 4from sphinx_codelinks.needextend_write import convert_marked_content
 5
 6
 7@pytest.mark.parametrize(
 8    ("markers", "texts"),
 9    [
10        (
11            [
12                {
13                    "filepath": "/home/jui-wen/git_repo/ub/sphinx-codelinks/tests/data/need_id_refs/dummy_1.cpp",
14                    "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3",
15                    "source_map": {
16                        "start": {"row": 2, "column": 13},
17                        "end": {"row": 2, "column": 51},
18                    },
19                    "tagged_scope": "void dummy_func1(){\n     //...\n }",
20                    "need_ids": ["NEED_001", "NEED_002", "NEED_003", "NEED_004"],
21                    "marker": "@need-ids:",
22                    "type": "need-id-refs",
23                },
24            ],
25            [
26                ".. needextend:: NEED_001\n   :remote-url: https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3\n\n",
27                ".. needextend:: NEED_002\n   :remote-url: https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3\n\n",
28                ".. needextend:: NEED_003\n   :remote-url: https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3\n\n",
29                ".. needextend:: NEED_004\n   :remote-url: https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3\n\n",
30            ],
31        ),
32        (
33            [
34                {
35                    "filepath": "/home/jui-wen/git_repo/ub/sphinx-codelinks/tests/data/need_id_refs/dummy_1.cpp",
36                    "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3",
37                    "source_map": {
38                        "start": {"row": 2, "column": 13},
39                        "end": {"row": 2, "column": 51},
40                    },
41                    "tagged_scope": "void dummy_func1(){\n     //...\n }",
42                    "need_ids": ["NEED_001"],
43                    "marker": "@need-ids:",
44                    "type": "need-id-refs",
45                },
46                {
47                    "filepath": "/home/jui-wen/git_repo/ub/sphinx-codelinks/tests/data/need_id_refs/dummy_1.cpp",
48                    "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L10",
49                    "source_map": {
50                        "start": {"row": 2, "column": 13},
51                        "end": {"row": 2, "column": 51},
52                    },
53                    "tagged_scope": "void dummy_func1(){\n     //...\n }",
54                    "need_ids": ["NEED_001"],
55                    "marker": "@need-ids:",
56                    "type": "need-id-refs",
57                },
58            ],
59            [
60                ".. needextend:: NEED_001\n   :remote-url: https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L3,https://github.com/useblocks/sphinx-codelinks/blob/main/tests/data/need_id_refs/dummy_1.cpp#L10\n\n"
61            ],
62        ),
63    ],
64)
65def test_convert_marked_content(markers, texts):
66    # Normalize line endings
67    texts = [line.replace("\r\n", "\n").replace("\r", "\n") for line in texts]
68    needextend_texts, errors = convert_marked_content(markers)
69
70    assert not errors
71
72    assert needextend_texts == texts