Skip to content

Commit 66c5e22

Browse files
committed
Use correct filename for custom stylesheet
- add unit test for ZipParatextProjectSettingsParser
1 parent 8d5fd21 commit 66c5e22

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public FileParatextProjectSettingsParser(string projectDir)
1414

1515
protected override UsfmStylesheet CreateStylesheet(string fileName)
1616
{
17-
string customStylesheetFileName = Path.Combine(_projectDir, fileName);
17+
string customStylesheetFileName = Path.Combine(_projectDir, "custom.sty");
1818
return new UsfmStylesheet(
1919
fileName,
2020
File.Exists(customStylesheetFileName) ? customStylesheetFileName : null
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using NUnit.Framework;
2+
3+
namespace SIL.Machine.Corpora;
4+
5+
public class FileParatextProjectSettingsParserTests
6+
{
7+
[Test]
8+
public void Parse_CustomStylesheet()
9+
{
10+
FileParatextProjectSettingsParser parser = new(CorporaTestHelpers.UsfmTestProjectPath);
11+
ParatextProjectSettings settings = parser.Parse();
12+
UsfmTag testTag = settings.Stylesheet.GetTag("test");
13+
Assert.That(testTag.StyleType, Is.EqualTo(UsfmStyleType.Character));
14+
Assert.That(testTag.TextType, Is.EqualTo(UsfmTextType.Other));
15+
}
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\Marker test
2+
\Endmarker test*
3+
\TextType Other
4+
\StyleType Character
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.IO.Compression;
2+
using NUnit.Framework;
3+
using SIL.ObjectModel;
4+
5+
namespace SIL.Machine.Corpora;
6+
7+
public class ZipParatextProjectSettingsParserTests
8+
{
9+
[Test]
10+
public void Parse_CustomStylesheet()
11+
{
12+
using var env = new TestEnvironment();
13+
ParatextProjectSettings settings = env.Parser.Parse();
14+
UsfmTag testTag = settings.Stylesheet.GetTag("test");
15+
Assert.That(testTag.StyleType, Is.EqualTo(UsfmStyleType.Character));
16+
Assert.That(testTag.TextType, Is.EqualTo(UsfmTextType.Other));
17+
}
18+
19+
private class TestEnvironment : DisposableBase
20+
{
21+
private readonly string _backupPath;
22+
private readonly ZipArchive _archive;
23+
24+
public TestEnvironment()
25+
{
26+
_backupPath = CorporaTestHelpers.CreateTestParatextBackup();
27+
_archive = ZipFile.OpenRead(_backupPath);
28+
Parser = new ZipParatextProjectSettingsParser(_archive);
29+
}
30+
31+
public ZipParatextProjectSettingsParser Parser { get; }
32+
33+
protected override void DisposeManagedResources()
34+
{
35+
_archive.Dispose();
36+
if (File.Exists(_backupPath))
37+
File.Delete(_backupPath);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)