diff --git a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs index f7e9d5b7..363209ed 100644 --- a/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs +++ b/src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs @@ -175,6 +175,11 @@ public override void Text(UsfmParserState state, string text) CheckConvertVerseParaToNonVerse(state); } + public override void OptBreak(UsfmParserState state) + { + CheckConvertVerseParaToNonVerse(state); + } + public override void StartChar( UsfmParserState state, string markerWithoutPlus, diff --git a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs index 3cb84df1..e0712e45 100644 --- a/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs @@ -83,7 +83,7 @@ public void GetRows_DuplicateVerseWithTable() includeAllText: true ); - Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.ToList().Select(tr => tr.Text))); + Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.Select(tr => tr.Text))); } [Test] @@ -104,17 +104,36 @@ public void GetRows_TriplicateVerse() ); Assert.Multiple(() => { - Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.ToList().Select(tr => tr.Text))); + Assert.That(rows, Has.Length.EqualTo(5), string.Join(",", rows.Select(tr => tr.Text))); Assert.That(rows[0].Text, Is.EqualTo("First verse 1")); Assert.That(rows[3].Text, Is.EqualTo("non verse 3")); Assert.That(rows[4].Text, Is.EqualTo("Second verse")); }); } + [Test] + public void GetRows_OptBreak_MiddleIncludeMarkers() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\c 1 +\v 1 First verse in line // More text +\c 2 +\v 1 +", + includeAllText: true, + includeMarkers: true + ); + Assert.Multiple(() => + { + Assert.That(rows, Has.Length.EqualTo(2), string.Join(",", rows.Select(tr => tr.Text))); + Assert.That(rows[0].Text, Is.EqualTo(@"First verse in line // More text")); + }); + } + [Test] public void GetRows_VersePara_BeginningNonVerseSegment() { - // a verse paragraph that begins with a non-verse segment followed by a verse segment TextRow[] rows = GetRows( @"\id MAT - Test \c 1 @@ -129,7 +148,40 @@ public void GetRows_VersePara_BeginningNonVerseSegment() includeAllText: true ); - Assert.That(rows, Has.Length.EqualTo(4), string.Join(",", rows.ToList().Select(tr => tr.Text))); + Assert.That(rows, Has.Length.EqualTo(4), string.Join(",", rows.Select(tr => tr.Text))); + } + + [Test] + public void GetRows_OptBreak_Beginning() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\li // +", + includeAllText: true + ); + Assert.Multiple(() => + { + Assert.That(rows, Has.Length.EqualTo(1), string.Join(",", rows.Select(tr => tr.Text))); + Assert.That(rows[0].Text, Is.EqualTo("")); + }); + } + + [Test] + public void GetRows_OptBreak_BeginningIncludeMarkers() + { + TextRow[] rows = GetRows( + @"\id MAT - Test +\li // +", + 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("//")); + }); } private static TextRow[] GetRows(string usfm, bool includeMarkers = false, bool includeAllText = false)