-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to Paratext project settings parser (#163)
- add ParatextProjectSettings.GetBookFileName() - add ZipParatextProjectSettingsParserBase class
- Loading branch information
Showing
4 changed files
with
161 additions
and
35 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
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
46 changes: 46 additions & 0 deletions
46
src/SIL.Machine/Corpora/ZipParatextProjectSettingsParserBase.cs
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,46 @@ | ||
using System.IO; | ||
using SIL.IO; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
public abstract class ZipParatextProjectSettingsParserBase : ParatextProjectSettingsParserBase | ||
{ | ||
protected override UsfmStylesheet CreateStylesheet(string fileName) | ||
{ | ||
TempFile stylesheetTempFile = null; | ||
TempFile customStylesheetTempFile = null; | ||
try | ||
{ | ||
string stylesheetPath = fileName; | ||
if (Exists(fileName)) | ||
{ | ||
stylesheetTempFile = TempFile.CreateAndGetPathButDontMakeTheFile(); | ||
using (Stream source = Open(fileName)) | ||
using (Stream target = File.OpenWrite(stylesheetTempFile.Path)) | ||
{ | ||
source.CopyTo(target); | ||
} | ||
stylesheetPath = stylesheetTempFile.Path; | ||
} | ||
|
||
string customStylesheetPath = null; | ||
if (Exists("custom.sty")) | ||
{ | ||
customStylesheetTempFile = TempFile.CreateAndGetPathButDontMakeTheFile(); | ||
using (Stream source = Open("custom.sty")) | ||
using (Stream target = File.OpenWrite(customStylesheetTempFile.Path)) | ||
{ | ||
source.CopyTo(target); | ||
} | ||
customStylesheetPath = customStylesheetTempFile.Path; | ||
} | ||
return new UsfmStylesheet(stylesheetPath, customStylesheetPath); | ||
} | ||
finally | ||
{ | ||
stylesheetTempFile?.Dispose(); | ||
customStylesheetTempFile?.Dispose(); | ||
} | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
tests/SIL.Machine.Tests/Corpora/ParatextProjectSettingsTests.cs
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,83 @@ | ||
using System.Text; | ||
using NUnit.Framework; | ||
using SIL.Scripture; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
[TestFixture] | ||
public class ParatextProjectSettingsTests | ||
{ | ||
[Test] | ||
public void GetBookFileName_BookNum() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("MRK"), Is.EqualTo("PROJ42.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumBookId() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41MAT"); | ||
Assert.That(settings.GetBookFileName("MRK"), Is.EqualTo("PROJ42MRK.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookId() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("MAT"); | ||
Assert.That(settings.GetBookFileName("MRK"), Is.EqualTo("PROJMRK.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumDoubleDigit() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("GEN"), Is.EqualTo("PROJ01.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumXXG() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("XXG"), Is.EqualTo("PROJ100.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumPrefixA() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("FRT"), Is.EqualTo("PROJA0.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumPrefixB() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("TDX"), Is.EqualTo("PROJB0.SFM")); | ||
} | ||
|
||
[Test] | ||
public void GetBookFileName_BookNumPrefixC() | ||
{ | ||
ParatextProjectSettings settings = CreateSettings("41"); | ||
Assert.That(settings.GetBookFileName("3MQ"), Is.EqualTo("PROJC0.SFM")); | ||
} | ||
|
||
private static ParatextProjectSettings CreateSettings(string fileNameForm) | ||
{ | ||
return new ParatextProjectSettings( | ||
"Name", | ||
"Name", | ||
Encoding.UTF8, | ||
ScrVers.English, | ||
new UsfmStylesheet("usfm.sty"), | ||
"PROJ", | ||
fileNameForm, | ||
".SFM", | ||
"Major", | ||
"", | ||
"BiblicalTerms.xml" | ||
); | ||
} | ||
} | ||
} |