CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job. - One naming rule (FrameNaming) for import, upload and Reorganize. - Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder. - Writers refuse a folder another program moved or gave to another sequence. - Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules. - Phase 3 docs and translations merged; strings in all 38 languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
155 lines
6.1 KiB
C#
155 lines
6.1 KiB
C#
using Chronos.Core.Naming;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Core.Tests.Naming;
|
|
|
|
public sealed class PathTemplateTests
|
|
{
|
|
private static readonly NamingContext Frame = new()
|
|
{
|
|
CapturedAt = new DateTime(2026, 9, 28, 18, 2, 11, 250),
|
|
SessionStart = new DateTime(2026, 9, 28, 18, 2, 11),
|
|
Session = 2,
|
|
Number = 1,
|
|
NumberInSession = 1,
|
|
CameraMake = "Canon",
|
|
CameraModel = "Canon EOS R5",
|
|
Lens = "RF24-70mm F2.8 L IS USM",
|
|
Iso = 400,
|
|
ExposureTime = 1.0 / 8,
|
|
FNumber = 8,
|
|
OriginalName = "IMG_0001",
|
|
Extension = "CR2",
|
|
Title = "Harbour sunset",
|
|
};
|
|
|
|
[Test]
|
|
public void DefaultTemplatesMatchTheBriefExample()
|
|
{
|
|
Assert.Equal("2026/2026-09-28 Canon EOS R5", PathTemplate.Parse(TemplateDefaults.Folder).ExpandFolder(Frame));
|
|
Assert.Equal("2026-09-28_18-02-11_0001.CR2", PathTemplate.Parse(TemplateDefaults.File).ExpandFile(Frame));
|
|
}
|
|
|
|
[Theory]
|
|
[Case("{n:000000}", "000001.CR2")]
|
|
[Case("{date:yyyyMMdd}_{name}", "20260928_IMG_0001.CR2")]
|
|
[Case("{iso}_{shutter}_{aperture}", "400_1-8_f8.CR2")]
|
|
[Case("{name}.{ext}", "IMG_0001.CR2")]
|
|
[Case("{{literal}}_{n}", "{literal}_0001.CR2")]
|
|
[Case("{session}-{nsession:00}", "2-01.CR2")]
|
|
public void FileTokens(string template, string expected) =>
|
|
Assert.Equal(expected, PathTemplate.Parse(template).ExpandFile(Frame));
|
|
|
|
[Test]
|
|
public void IllegalCharactersAreReplaced()
|
|
{
|
|
var context = Frame with { Title = "a:b*c?<d>|e\"f" };
|
|
Assert.Equal("a_b_c__d__e_f.CR2", PathTemplate.Parse("{title}").ExpandFile(context));
|
|
}
|
|
|
|
[Test]
|
|
public void TokenValuesNeverCreateFolders()
|
|
{
|
|
var context = Frame with { Lens = "18/55 mm" };
|
|
Assert.Equal("2026/18-55 mm", PathTemplate.Parse("{year}/{lens}").ExpandFolder(context));
|
|
}
|
|
|
|
[Test]
|
|
public void ReservedWindowsNamesAreEscaped() =>
|
|
Assert.Equal("_CON.CR2", PathTemplate.Parse("{title}").ExpandFile(Frame with { Title = "CON" }));
|
|
|
|
[Theory]
|
|
[Case(".NET Conf", "2026/_.NET Conf")]
|
|
[Case("Exports", "2026/_Exports")]
|
|
[Case("originals", "2026/_originals")]
|
|
[Case("PROXIES", "2026/_PROXIES")]
|
|
[Case(".chronos", "2026/_.chronos")]
|
|
[Case("Harbour", "2026/Harbour")]
|
|
public void FolderLevelsScansNeverEnterAreEscaped(string title, string expected)
|
|
{
|
|
var template = PathTemplate.Parse("{year}/{title}");
|
|
Assert.Equal(expected, template.ExpandFolder(Frame with { Title = title }));
|
|
Assert.Equal(title != "Harbour", template.WritesHiddenFolder(Frame with { Title = title }));
|
|
Assert.Equal(title != "Harbour", PathTemplate.IsHiddenFolder(title));
|
|
}
|
|
|
|
[Theory]
|
|
[Case("{n}", true)]
|
|
[Case("{name}.{ext}", true)]
|
|
[Case("{n} .{ext}", true)]
|
|
[Case("{n}.CR3", true)]
|
|
[Case("{n}{ext}", false)]
|
|
[Case("{n}_{ext}", false)]
|
|
[Case("{n}. {ext}", false)]
|
|
[Case("{n}.{ext}{ext}", false)]
|
|
public void AFileTemplateKeepsTheExtensionOnlyWithItsDot(string template, bool keeps)
|
|
{
|
|
var parsed = PathTemplate.Parse(template);
|
|
Assert.Equal(keeps, parsed.KeepsExtension, template);
|
|
Assert.Equal(keeps, parsed.ExpandFile(Frame).EndsWith(".CR2", StringComparison.Ordinal), parsed.ExpandFile(Frame));
|
|
}
|
|
|
|
[Test]
|
|
public void ALongNameIsShortenedBeforeItsExtension()
|
|
{
|
|
// A title as long as titles go: the number gives way, the extension never does.
|
|
var title = new string('a', 195);
|
|
var name = PathTemplate.Parse("{title}_{n:0000}.{ext}").ExpandFile(Frame with { Title = title });
|
|
Assert.Equal(title + "_.CR2", name);
|
|
Assert.Equal(PathTemplate.MaxSegmentLength, name.Length);
|
|
// Appended, the extension comes after the longest name.
|
|
Assert.Equal(title + "_0001.CR2", PathTemplate.Parse("{title}_{n:0000}").ExpandFile(Frame with { Title = title }));
|
|
// Short names are as they were.
|
|
Assert.Equal("Harbour sunset_0001.CR2", PathTemplate.Parse("{title}_{n:0000}.{ext}").ExpandFile(Frame));
|
|
}
|
|
|
|
[Theory]
|
|
[Case("{title} 2026", "Paris: night", "Paris: night 2026")]
|
|
[Case("{title} 2026", "24/7 roof", "24/7 roof 2026")]
|
|
[Case("{title}", "Aux. trip", "Aux. trip")]
|
|
[Case("{title}", "What?", "What?")]
|
|
[Case("{title}", "Sunset...", "Sunset...")]
|
|
[Case(" {title}\t", "Dawn", "Dawn")]
|
|
public void TitlesAreTextNotFileNames(string template, string title, string expected) =>
|
|
Assert.Equal(expected, PathTemplate.Parse(template).ExpandText(Frame with { Title = title }));
|
|
|
|
[Test]
|
|
public void TextKeepsToTheLongestTitle()
|
|
{
|
|
var text = PathTemplate.Parse("{title}{title}").ExpandText(Frame with { Title = new string('a', 150) });
|
|
Assert.Equal(PathTemplate.MaxTextLength, text.Length);
|
|
// A character outside the basic plane is never cut in two.
|
|
var emoji = PathTemplate.Parse("{title}").ExpandText(Frame with { Title = new string('a', 199) + "\U0001F305" });
|
|
Assert.Equal(new string('a', 199), emoji);
|
|
}
|
|
|
|
[Test]
|
|
public void ErrorsCarryPositionAndToken()
|
|
{
|
|
var t = PathTemplate.Parse("{date}_{bogus}_{n");
|
|
Assert.False(t.IsValid);
|
|
Assert.Contains(new TemplateError(7, "UnknownToken", "bogus"), t.Errors);
|
|
Assert.Contains(t.Errors, e => e.Code == "UnclosedBrace");
|
|
}
|
|
|
|
[Test]
|
|
public void EmptyExpansionFallsBackToOriginalName() =>
|
|
Assert.Equal("IMG_0001.CR2", PathTemplate.Parse("{title}").ExpandFile(Frame with { Title = null }));
|
|
|
|
[Theory]
|
|
[Case("NIKON CORPORATION", "NIKON Z 8", "Nikon Z 8")]
|
|
[Case("SONY", "ILCE-7M4", "SONY ILCE-7M4")]
|
|
[Case("Canon", "Canon EOS R5", "Canon EOS R5")]
|
|
[Case(null, "HERO12 Black", "HERO12 Black")]
|
|
public void CameraNameAvoidsDuplicatedBrand(string? make, string model, string expected) =>
|
|
Assert.Equal(expected, PathTemplate.CameraName(make, model));
|
|
|
|
[Test]
|
|
public void ShutterFormatting()
|
|
{
|
|
Assert.Equal("1-250", PathTemplate.Shutter(0.004));
|
|
Assert.Equal("2s", PathTemplate.Shutter(2));
|
|
Assert.Equal(string.Empty, PathTemplate.Shutter(null));
|
|
}
|
|
}
|