diff --git a/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs b/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs index d5331ec3..996400a4 100644 --- a/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs +++ b/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs @@ -14,7 +14,7 @@ public FileParatextProjectSettingsParser(string projectDir) protected override UsfmStylesheet CreateStylesheet(string fileName) { - string customStylesheetFileName = Path.Combine(_projectDir, fileName); + string customStylesheetFileName = Path.Combine(_projectDir, "custom.sty"); return new UsfmStylesheet( fileName, File.Exists(customStylesheetFileName) ? customStylesheetFileName : null diff --git a/tests/SIL.Machine.Tests/Corpora/FileParatextProjectSettingsParserTests.cs b/tests/SIL.Machine.Tests/Corpora/FileParatextProjectSettingsParserTests.cs new file mode 100644 index 00000000..058cffd6 --- /dev/null +++ b/tests/SIL.Machine.Tests/Corpora/FileParatextProjectSettingsParserTests.cs @@ -0,0 +1,16 @@ +using NUnit.Framework; + +namespace SIL.Machine.Corpora; + +public class FileParatextProjectSettingsParserTests +{ + [Test] + public void Parse_CustomStylesheet() + { + FileParatextProjectSettingsParser parser = new(CorporaTestHelpers.UsfmTestProjectPath); + ParatextProjectSettings settings = parser.Parse(); + UsfmTag testTag = settings.Stylesheet.GetTag("test"); + Assert.That(testTag.StyleType, Is.EqualTo(UsfmStyleType.Character)); + Assert.That(testTag.TextType, Is.EqualTo(UsfmTextType.Other)); + } +} diff --git a/tests/SIL.Machine.Tests/Corpora/TestData/usfm/Tes/custom.sty b/tests/SIL.Machine.Tests/Corpora/TestData/usfm/Tes/custom.sty new file mode 100644 index 00000000..24c0602f --- /dev/null +++ b/tests/SIL.Machine.Tests/Corpora/TestData/usfm/Tes/custom.sty @@ -0,0 +1,4 @@ +\Marker test +\Endmarker test* +\TextType Other +\StyleType Character diff --git a/tests/SIL.Machine.Tests/Corpora/ZipParatextProjectSettingsParserTests.cs b/tests/SIL.Machine.Tests/Corpora/ZipParatextProjectSettingsParserTests.cs new file mode 100644 index 00000000..0c58100b --- /dev/null +++ b/tests/SIL.Machine.Tests/Corpora/ZipParatextProjectSettingsParserTests.cs @@ -0,0 +1,40 @@ +using System.IO.Compression; +using NUnit.Framework; +using SIL.ObjectModel; + +namespace SIL.Machine.Corpora; + +public class ZipParatextProjectSettingsParserTests +{ + [Test] + public void Parse_CustomStylesheet() + { + using var env = new TestEnvironment(); + ParatextProjectSettings settings = env.Parser.Parse(); + UsfmTag testTag = settings.Stylesheet.GetTag("test"); + Assert.That(testTag.StyleType, Is.EqualTo(UsfmStyleType.Character)); + Assert.That(testTag.TextType, Is.EqualTo(UsfmTextType.Other)); + } + + private class TestEnvironment : DisposableBase + { + private readonly string _backupPath; + private readonly ZipArchive _archive; + + public TestEnvironment() + { + _backupPath = CorporaTestHelpers.CreateTestParatextBackup(); + _archive = ZipFile.OpenRead(_backupPath); + Parser = new ZipParatextProjectSettingsParser(_archive); + } + + public ZipParatextProjectSettingsParser Parser { get; } + + protected override void DisposeManagedResources() + { + _archive.Dispose(); + if (File.Exists(_backupPath)) + File.Delete(_backupPath); + } + } +}