Skip to content

Commit 707119c

Browse files
committed
update remark test and ensure remarks are added at the end of existing chapter remarks
1 parent 1e2e999 commit 707119c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

machine/corpora/update_usfm_parser_handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ def get_usfm(self, stylesheet: Union[str, UsfmStylesheet] = "usfm.sty") -> str:
347347
if len(tokens) > 0:
348348
for index, token in enumerate(tokens):
349349
if token.type == UsfmTokenType.CHAPTER:
350-
tokens[index + 1 : index + 1] = remark_tokens
350+
insertion_index = index + 1
351+
while insertion_index < len(tokens) and tokens[insertion_index].marker == "rem":
352+
insertion_index += 1
353+
if insertion_index < len(tokens) and tokens[insertion_index].type == UsfmTokenType.TEXT:
354+
insertion_index += 1
355+
tokens[insertion_index:insertion_index] = remark_tokens
351356
return tokenizer.detokenize(tokens)
352357

353358
def _advance_rows(self, seg_scr_refs: Sequence[ScriptureRef]) -> Tuple[List[str], Optional[dict[str, object]]]:

tests/corpora/test_update_usfm_parser_handler.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,17 +1389,22 @@ def test_pass_remark():
13891389
\v 1 Some text
13901390
\v 2
13911391
\v 3 Other text
1392+
\c 2
1393+
\v 1 More text
13921394
"""
13931395

13941396
target = update_usfm(rows, usfm, text_behavior=UpdateUsfmTextBehavior.PREFER_EXISTING, remarks=["New remark"])
13951397
result = r"""\id MAT - Test
13961398
\ide UTF-8
13971399
\rem Existing remark
1398-
\rem New remark
13991400
\c 1
1401+
\rem New remark
14001402
\v 1 Some text
14011403
\v 2 Update 2
14021404
\v 3 Other text
1405+
\c 2
1406+
\rem New remark
1407+
\v 1 More text
14031408
"""
14041409

14051410
assert_usfm_equals(target, result)
@@ -1408,12 +1413,16 @@ def test_pass_remark():
14081413
result = r"""\id MAT - Test
14091414
\ide UTF-8
14101415
\rem Existing remark
1416+
\c 1
14111417
\rem New remark
14121418
\rem New remark 2
1413-
\c 1
14141419
\v 1 Some text
14151420
\v 2 Update 2
14161421
\v 3 Other text
1422+
\c 2
1423+
\rem New remark
1424+
\rem New remark 2
1425+
\v 1 More text
14171426
"""
14181427

14191428
assert_usfm_equals(target, result)

0 commit comments

Comments
 (0)