diff --git a/src/SIL.Machine/Corpora/ZipParatextProjecTextUpdater.cs b/src/SIL.Machine/Corpora/ZipParatextProjecTextUpdater.cs new file mode 100644 index 00000000..c8bc8f5d --- /dev/null +++ b/src/SIL.Machine/Corpora/ZipParatextProjecTextUpdater.cs @@ -0,0 +1,29 @@ +using System.IO; +using System.IO.Compression; + +namespace SIL.Machine.Corpora +{ + public class ZipParatextProjectTextUpdater : ZipParatextProjectTextUpdaterBase + { + private readonly ZipArchive _archive; + + public ZipParatextProjectTextUpdater(ZipArchive archive) + : base(new ZipParatextProjectSettingsParser(archive)) + { + _archive = archive; + } + + protected override bool Exists(string fileName) + { + return _archive.GetEntry(fileName) != null; + } + + protected override Stream Open(string fileName) + { + ZipArchiveEntry entry = _archive.GetEntry(fileName); + if (entry == null) + return null; + return entry.Open(); + } + } +} diff --git a/src/SIL.Machine/Corpora/ZipParatextProjectTextUpdaterBase.cs b/src/SIL.Machine/Corpora/ZipParatextProjectTextUpdaterBase.cs new file mode 100644 index 00000000..02993a57 --- /dev/null +++ b/src/SIL.Machine/Corpora/ZipParatextProjectTextUpdaterBase.cs @@ -0,0 +1,8 @@ +namespace SIL.Machine.Corpora +{ + public abstract class ZipParatextProjectTextUpdaterBase : ParatextProjectTextUpdaterBase + { + protected ZipParatextProjectTextUpdaterBase(ParatextProjectSettingsParserBase settingsParser) + : base(settingsParser) { } + } +} diff --git a/tests/SIL.Machine.Tests/Corpora/UpdateUsfmParserHandlerTests.cs b/tests/SIL.Machine.Tests/Corpora/UpdateUsfmParserHandlerTests.cs index ad6ce166..51cde197 100644 --- a/tests/SIL.Machine.Tests/Corpora/UpdateUsfmParserHandlerTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/UpdateUsfmParserHandlerTests.cs @@ -21,7 +21,7 @@ public void GetUsfm_Verse_CharStyle() [Test] public void GetUsfm_IdText() { - string target = UpdateUsfm(idText: "- Updated"); + string target = UpdateUsfm(idText: "Updated"); Assert.That(target, Contains.Substring("\\id MAT - Updated\r\n")); } @@ -443,21 +443,27 @@ private static string UpdateUsfm( ) { if (source is null) - source = ReadUsfm(); + { + var updater = new FileParatextProjectTextUpdater(CorporaTestHelpers.UsfmTestProjectPath); + return updater.UpdateUsfm( + "MAT", + rows, + fullName: idText, + stripAllText: stripAllText, + preferExistingText: preferExistingText + ); + } else + { source = source.Trim().ReplaceLineEndings("\r\n") + "\r\n"; - var updater = new UpdateUsfmParserHandler( - rows, - idText, - stripAllText: stripAllText, - preferExistingText: preferExistingText - ); - UsfmParser.Parse(source, updater); - return updater.GetUsfm(); - } - - private static string ReadUsfm() - { - return File.ReadAllText(Path.Combine(CorporaTestHelpers.UsfmTestProjectPath, "41MATTes.SFM")); + var updater = new UpdateUsfmParserHandler( + rows, + idText, + stripAllText: stripAllText, + preferExistingText: preferExistingText + ); + UsfmParser.Parse(source, updater); + return updater.GetUsfm(); + } } }