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 =