Skip to content

Commit

Permalink
Draft: Fill in zip classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Aug 1, 2024
1 parent d2db1aa commit b140176
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
29 changes: 29 additions & 0 deletions src/SIL.Machine/Corpora/ZipParatextProjecTextUpdater.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
8 changes: 8 additions & 0 deletions src/SIL.Machine/Corpora/ZipParatextProjectTextUpdaterBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SIL.Machine.Corpora
{
public abstract class ZipParatextProjectTextUpdaterBase : ParatextProjectTextUpdaterBase
{
protected ZipParatextProjectTextUpdaterBase(ParatextProjectSettingsParserBase settingsParser)
: base(settingsParser) { }
}
}
36 changes: 21 additions & 15 deletions tests/SIL.Machine.Tests/Corpora/UpdateUsfmParserHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit b140176

Please sign in to comment.