-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove obsolete handling of \d marker (#216)
- fixes sillsdev/serval#416 - add UsfmMemoryText for testing - add support for isolated testing of USFM parsing/generation
- Loading branch information
Showing
6 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.IO; | ||
using System.Text; | ||
using SIL.ObjectModel; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
public class MemoryStreamContainer : DisposableBase, IStreamContainer | ||
{ | ||
private readonly string _usfm; | ||
|
||
public MemoryStreamContainer(string usfm) | ||
{ | ||
_usfm = usfm; | ||
} | ||
|
||
public Stream OpenStream() | ||
{ | ||
return new MemoryStream(Encoding.UTF8.GetBytes(_usfm)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Text; | ||
using SIL.Scripture; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
public class UsfmMemoryText : UsfmTextBase | ||
{ | ||
private readonly string _usfm; | ||
|
||
public UsfmMemoryText( | ||
UsfmStylesheet stylesheet, | ||
Encoding encoding, | ||
string id, | ||
string usfm, | ||
ScrVers versification = null, | ||
bool includeMarkers = false, | ||
bool includeAllText = false | ||
) | ||
: base(id, stylesheet, encoding, versification, includeMarkers, includeAllText) | ||
{ | ||
_usfm = usfm; | ||
} | ||
|
||
protected override IStreamContainer CreateStreamContainer() | ||
{ | ||
return new MemoryStreamContainer(_usfm); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Text; | ||
using NUnit.Framework; | ||
|
||
namespace SIL.Machine.Corpora; | ||
|
||
[TestFixture] | ||
public class UsfmMemoryTextTests | ||
{ | ||
[Test] | ||
public void GetRows_VerseDescriptiveTitle() | ||
{ | ||
TextRow[] rows = GetRows( | ||
@"\id MAT - Test | ||
\c 1 | ||
\d | ||
\v 1 Descriptive title | ||
\c 2 | ||
\b | ||
\q1 | ||
\s | ||
" | ||
); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(rows, Has.Length.EqualTo(1)); | ||
Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1"))); | ||
Assert.That(rows[0].Text, Is.EqualTo("Descriptive title")); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void GetRows_LastSegment() | ||
{ | ||
TextRow[] rows = GetRows( | ||
@"\id MAT - Test | ||
\c 1 | ||
\v 1 Last segment | ||
" | ||
); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(rows, Has.Length.EqualTo(1)); | ||
Assert.That(rows[0].Ref, Is.EqualTo(ScriptureRef.Parse("MAT 1:1"))); | ||
Assert.That(rows[0].Text, Is.EqualTo("Last segment")); | ||
}); | ||
} | ||
|
||
private static TextRow[] GetRows(string usfm, bool includeMarkers = false, bool includeAllText = false) | ||
{ | ||
UsfmMemoryText text = | ||
new( | ||
new UsfmStylesheet("usfm.sty"), | ||
Encoding.UTF8, | ||
"MAT", | ||
usfm.Trim().ReplaceLineEndings("\r\n") + "\r\n", | ||
includeMarkers: includeMarkers, | ||
includeAllText: includeAllText | ||
); | ||
return text.GetRows().ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters