Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes https://github.com/sillsdev/serval/issues/449 #232

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/SIL.Machine/Corpora/ScriptureRefUsfmParserHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
60 changes: 56 additions & 4 deletions tests/SIL.Machine.Tests/Corpora/UsfmMemoryTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading