Skip to content

Commit 4373ea3

Browse files
committed
[#51] Fix leading and trailing space handling in oneline_parser and add corresponding test cases
1 parent cb37a48 commit 4373ea3

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/sphinx_codelinks/analyse/oneline_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def oneline_parser( # noqa: PLR0912, PLR0911 # handel warnings
5454

5555
# extract the string wrapped by start and end
5656
start_idx = start_idx + len(oneline_config.start_sequence)
57-
string = oneline[start_idx:end_idx]
57+
string = oneline[start_idx:end_idx].strip()
5858

5959
# numbers of needs_fields which are required
6060
cnt_required_fields = oneline_config.get_cnt_required_fields()

tests/test_oneline_parser.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,54 @@
2525
"end_column": 17,
2626
},
2727
),
28+
# Test case for leading space after start sequence (bug fix)
29+
(
30+
f"@ title 1, IMPL_1 {UNIX_NEWLINE}",
31+
{
32+
"title": "title 1",
33+
"id": "IMPL_1",
34+
"type": "impl",
35+
"links": [],
36+
"start_column": 1,
37+
"end_column": 18,
38+
},
39+
),
40+
# Test case for multiple leading spaces after start sequence
41+
(
42+
f"@ title 1, IMPL_1 {UNIX_NEWLINE}",
43+
{
44+
"title": "title 1",
45+
"id": "IMPL_1",
46+
"type": "impl",
47+
"links": [],
48+
"start_column": 1,
49+
"end_column": 20,
50+
},
51+
),
52+
# Test case for trailing space before end sequence
53+
(
54+
f"@title 1, IMPL_1 {UNIX_NEWLINE}",
55+
{
56+
"title": "title 1",
57+
"id": "IMPL_1",
58+
"type": "impl",
59+
"links": [],
60+
"start_column": 1,
61+
"end_column": 18,
62+
},
63+
),
64+
# Test case for both leading and trailing spaces
65+
(
66+
f"@ title 1, IMPL_1 {UNIX_NEWLINE}",
67+
{
68+
"title": "title 1",
69+
"id": "IMPL_1",
70+
"type": "impl",
71+
"links": [],
72+
"start_column": 1,
73+
"end_column": 21,
74+
},
75+
),
2876
],
2977
)
3078
def test_oneline_parser_default_config_positive(

0 commit comments

Comments
 (0)