Files
Chronos/tests/Titano.App.Tests/Uploader/UploaderTextTests.cs
T
Claude 082ff1e3eb fix(i18n): tallies of participles read as labels
Texts that count with participles or adjectives still put a bare number in
front of a word that agrees with it in Italian, so one failure read "1 non
riuscite": the import result and its Done toast, the archive health line and
the thumbnail and import job log lines. They now read as labels in English and
Italian ("Copied: 40 · failed: 1"), like the scan and verify log lines; their
old translations leave the other 36 catalogs until the next translation pass.
The uploader's progress keeps the mockup's English and uses labels in Italian,
and the admin dashboard's upload total no longer agrees with the number.

`i18n check` now also fails on an English text that tallies two or more counts
with participles or adjectives. A single "{0} failed" is left alone, since the
placeholder there is as often a name or a size as a count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-12 11:09:17 +00:00

150 lines
6.1 KiB
C#

using System.Globalization;
using Titano.Testing;
using Titano.Uploader.Text;
using Titano.Uploader.Uploads;
namespace Titano.App.Tests.Uploader;
public sealed class UploaderTextTests
{
private static readonly CultureInfo En = CultureInfo.GetCultureInfo("en");
private static readonly CultureInfo It = CultureInfo.GetCultureInfo("it");
private static readonly QueueSummary Mockup = new(4_812, 96_200_000_000, 2_214, 2_201, 0, 0, 44_000_000_000, "2026-09-28_18-02-11_0413.CR2")
{
RemainingBytes = 93_480_000_000,
};
[Test]
public void QueueLineMatchesTheMockup()
{
var left = RateMeter.TimeLeft(Mockup.RemainingBytes, 38_000_000);
Assert.Equal("4,812 files · 96.2 GB · 38 MB/s · 41 min left", UploaderText.QueueLine(Mockup, QueueActivity.Running, 38_000_000, left, En));
}
[Test]
public void QueueLineFollowsTheCulture()
{
Assert.Equal("4.812 file · 96,2 GB · 38 MB/s · mancano 41 min", UploaderText.QueueLine(Mockup, QueueActivity.Running, 38_000_000, TimeSpan.FromMinutes(41), It));
}
[Test]
public void QueueLineNamesTheActivityWhenNotRunning()
{
Assert.Equal("4,812 files · 96.2 GB · Paused", UploaderText.QueueLine(Mockup, QueueActivity.Paused, 0, null, En));
Assert.Equal("4,812 files · 96.2 GB · Waiting for server", UploaderText.QueueLine(Mockup, QueueActivity.WaitingForServer, 0, null, En));
Assert.Equal("1 file · 25 MB · Done", UploaderText.QueueLine(Mockup with { Files = 1, Bytes = 25_000_000 }, QueueActivity.Done, 0, null, En));
Assert.Equal("Nothing queued", UploaderText.QueueLine(default, QueueActivity.Idle, 0, null, En));
}
[Test]
public void RunningLineOmitsRateAndTimeUntilKnown()
{
Assert.Equal("4,812 files · 96.2 GB", UploaderText.QueueLine(Mockup, QueueActivity.Running, 0, null, En));
}
[Test]
public void ProgressLineMatchesTheMockup()
{
Assert.Equal("2,214 of 4,812 sent · 2,201 verified by the server · 0 retries", UploaderText.ProgressLine(Mockup, En));
Assert.Equal("2,214 of 4,812 sent · 2,201 verified by the server · 1 retry", UploaderText.ProgressLine(Mockup with { Retries = 1, Failed = 3 }, En));
}
[Test]
public void FailuresHaveTheirOwnTextOnlyWhenThereAreAny()
{
Assert.Null(UploaderText.Failed(Mockup, En));
Assert.Equal("1,203 failed", UploaderText.Failed(Mockup with { Failed = 1_203 }, En));
// Italian participles agree with the number ("1 non riuscito", "3 non riusciti"): the count follows a label instead.
Assert.Equal("Non riusciti: 3", UploaderText.Failed(Mockup with { Failed = 3 }, It));
Assert.Equal("Non riusciti: 1", UploaderText.Failed(Mockup with { Failed = 1 }, It));
}
[Test]
public void ItalianProgressReadsForASingleFileToo()
{
Assert.Equal("Inviati: 1 di 1 · Verificati dal server: 1 · 0 nuovi tentativi",
UploaderText.ProgressLine(Mockup with { Files = 1, Sent = 1, Verified = 1 }, It));
}
[Test]
public void SizeUnitsFollowTheLanguage()
{
Assert.Equal("999 byte", UploaderText.Bytes(999, It));
Assert.Equal("1,5 KB", UploaderText.Bytes(1_536, It));
Assert.Equal("4,2 MB/s", UploaderText.Rate(4_240_000, It));
}
[Theory]
[Case(0.0, "0 B/s")]
[Case(950_000.0, "950 KB/s")]
[Case(4_240_000.0, "4.2 MB/s")]
[Case(38_400_000.0, "38 MB/s")]
[Case(1_260_000_000.0, "1.3 GB/s")]
public void RatesUseDecimalUnits(double bytesPerSecond, string expected) =>
Assert.Equal(expected, UploaderText.Rate(bytesPerSecond, En));
[Theory]
[Case(40.0, "40 s")]
[Case(299.0, "5 min")]
[Case(3_590.0, "1 h 00 m")]
[Case(7_500.0, "2 h 05 m")]
[Case(93_600.0, "1 d 2 h")]
public void DurationsAreCompact(double seconds, string expected) =>
Assert.Equal(expected, UploaderText.Duration(TimeSpan.FromSeconds(seconds), En));
[Theory]
[Case(999L, "999 B")]
[Case(1_536L, "1.5 KB")]
[Case(96_200_000_000L, "96.2 GB")]
[Case(1_900_000_000_000L, "1.9 TB")]
public void SizesUseDecimalUnits(long bytes, string expected) => Assert.Equal(expected, UploaderText.Bytes(bytes, En));
[Test]
public void TimeLeftNeedsAUsableRate()
{
Assert.Equal(TimeSpan.FromMinutes(41), RateMeter.TimeLeft(93_480_000_000, 38_000_000));
Assert.Equal(TimeSpan.Zero, RateMeter.TimeLeft(0, 0));
Assert.Null(RateMeter.TimeLeft(1_000, 10));
}
[Test]
public void RateMeterAveragesTheWindowAndDecaysWhenStalled()
{
var meter = new RateMeter(TimeSpan.FromSeconds(10));
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.Zero));
for (var s = 0; s <= 20; s++) meter.Add(4_000_000, TimeSpan.FromSeconds(s));
Assert.Approximately(4_000_000, meter.BytesPerSecond(TimeSpan.FromSeconds(20)), 1);
// Nothing sent for 20 s: the window holds no transfer any more.
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.FromSeconds(40)));
meter.Reset();
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.FromSeconds(40)));
}
[Test]
public void SummaryCountsStatesAndBytes()
{
var queue = new UploadQueue();
queue.Add(new UploadBatch { Id = Guid.CreateVersion7(), Mode = UploadTargetMode.Sessions },
Enumerable.Range(0, 5).Select(i => new QueueEntry($"{i}.jpg", 100, DateTime.UtcNow, null, null, null)));
queue.Items[0].State = UploadItemState.Verified;
queue.Items[1].State = UploadItemState.Skipped;
queue.Items[2].State = UploadItemState.Uploading;
queue.Items[2].BytesSent = 40;
queue.Items[3].State = UploadItemState.Failed;
queue.Items[3].Retries = 1;
var s = QueueSummary.From(queue.Items);
Assert.Equal(5, s.Files);
Assert.Equal(500L, s.Bytes);
Assert.Equal(2, s.Sent);
Assert.Equal(2, s.Verified);
Assert.Equal(1, s.Failed);
Assert.Equal(1, s.Retries);
Assert.Equal(240L, s.DoneBytes);
Assert.Equal(160L, s.RemainingBytes);
Assert.Equal("2.jpg", s.CurrentFile);
Assert.Approximately(0.48, s.Progress, 1e-9);
}
}