Skip to content

Commit

Permalink
tests(po): add new test case to test po files that dont have a msgctxt
Browse files Browse the repository at this point in the history
  • Loading branch information
RealLHI committed Sep 12, 2024
1 parent c745898 commit e163ddc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Ashampoo.Translation.Systems.Formats.PO/tests/FormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,41 @@ public void CreateBuilderWithDisabledPipeSplittingTest()
result.Should().NotContain("msgctxt ");
}

[Fact]
public void ReadWithoutMsgCtxtText()
{
var format = CreateAndReadFromFile("test.po",
new FormatReadOptions { SourceLanguage = new Language("en-US") });

var poHeader = format.Header as POHeader;
poHeader.Should().NotBeNull();

format.TranslationUnits.Count.Should().Be(2);
format.Header.TargetLanguage.Should().Be(new Language("de-DE"));

const string id = "testid2";

format.TranslationUnits.GetTranslationUnit(id).Translations.GetTranslation(new Language("de-DE")).Value.Should()
.Be("deutscher testid2 Text");
}

[Fact]
public async Task ReadAndWriteWithoutMsgCtxtText()
{
var format = await CreateAndReadFromFileAsync("test.po",
new FormatReadOptions { SourceLanguage = new Language("en-US") });

var outStream = new MemoryStream();
await format.WriteAsync(outStream);
await outStream.FlushAsync();
outStream.Seek(0, SeekOrigin.Begin);

var reader = new StreamReader(outStream);
var result = await reader.ReadToEndAsync();
result.Should().NotBeEmpty();
result.Should().NotContain("msgctxt ");
}

[Fact]
public async Task ReadAndWriteAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
msgid ""
msgstr ""
"Language: de-DE\n"

msgid "testid1"
msgstr "deutscher testid1 Text"

msgid "testid2"
msgstr "deutscher testid2 Text"

0 comments on commit e163ddc

Please sign in to comment.