From e78d2005212166b9022bdf995956a8792cdd833d Mon Sep 17 00:00:00 2001 From: Damien Daspit Date: Thu, 12 Sep 2024 13:35:42 -0500 Subject: [PATCH] Ignore opt break that occurs outside of a segment - fixes #242 --- src/SIL.Machine/Corpora/UsfmTextBase.cs | 3 +++ .../Corpora/UsfmMemoryTextTests.cs | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/SIL.Machine/Corpora/UsfmTextBase.cs b/src/SIL.Machine/Corpora/UsfmTextBase.cs index bdeb7578..af2820e4 100644 --- a/src/SIL.Machine/Corpora/UsfmTextBase.cs +++ b/src/SIL.Machine/Corpora/UsfmTextBase.cs @@ -218,6 +218,9 @@ public override void OptBreak(UsfmParserState state) { base.OptBreak(state); + if (_rowTexts.Count == 0) + return; + if (_text._includeMarkers) { _rowTexts.Peek().Append("//"); diff --git a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs index e0712e45..cab64288 100644 --- a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs @@ -184,6 +184,26 @@ public void GetRows_OptBreak_BeginningIncludeMarkers() }); } + [Test] + public void GetRows_OptBreak_OutsideOfSegment() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\c 1 +// +\p +\v 1 This is the first verse. +", + includeAllText: true, + includeMarkers: true + ); + Assert.Multiple(() => + { + Assert.That(rows, Has.Length.EqualTo(1), string.Join(",", rows.Select(tr => tr.Text))); + Assert.That(rows[0].Text, Is.EqualTo("This is the first verse.")); + }); + } + private static TextRow[] GetRows(string usfm, bool includeMarkers = false, bool includeAllText = false) { UsfmMemoryText text =