From 1699ad81545e04e6a7eb2ab0dca5b98a952b591c Mon Sep 17 00:00:00 2001 From: Damien Daspit Date: Wed, 17 Sep 2025 11:25:55 -0400 Subject: [PATCH] Use correct filename for custom stylesheet - add unit test for ZipParatextProjectSettingsParser --- .../FileParatextProjectSettingsParser.cs | 2 +- .../FileParatextProjectSettingsParserTests.cs | 16 ++++++++ .../Corpora/TestData/usfm/Tes/custom.sty | 4 ++ .../ZipParatextProjectSettingsParserTests.cs | 40 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/SIL.Machine.Tests/Corpora/FileParatextProjectSettingsParserTests.cs create mode 100644 tests/SIL.Machine.Tests/Corpora/TestData/usfm/Tes/custom.sty create mode 100644 tests/SIL.Machine.Tests/Corpora/ZipParatextProjectSettingsParserTests.cs diff --git a/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs b/src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs index d5331ec33..996400a4c 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 000000000..058cffd68 --- /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 000000000..24c0602f8 --- /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 000000000..0c58100bc --- /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); + } + } +}