fix(archive): Reorganize names as filing does and refuses templates that lose or hide photos
Reorganize with the archive's own templates planned renames and moves for
photos just filed, and some templates could strip extensions, hide sequences
from scans or stall a dry run. Owner review 2, phase 4a findings.
- Filing and Reorganize share one context: uploads and imports name every
photo with the sequence's camera and lens (its first photo's, or the
creator's hint), an upload's folder from its first frame in the new
sequence, and a missing capture time from the sequence start instead of
the current time. The planner expands folder and title templates from the
first frame in the sidecar ({name}, {ext}, {iso}...), never today's date.
- Titles expand as text (ExpandText): "Paris: night" stays as typed.
- A sequence whose sidecar cannot be read (torn, another sequence's) keeps
its folder, title and names, listed with why, and so does every folder
around it; the dry run reads every sidecar, nested ones included.
- Kept never gives one folder to two sequences of a plan whatever the case,
and a case-only move onto another folder is refused instead of taken as
done.
- Shared template rules (TemplateRules) for the server's Reorganize and
archive settings and the desktop's fields: a file template must keep the
photo's extension ("{n}{ext}" refused) and tell a session's photos apart;
a folder template may not write a level scans skip (a leading dot,
originals, proxies, exports). Levels a title gives are escaped with "_".
- {ext} comes from the file, or from the original name when the file lost
a photo's extension, so a Reorganize can put it back.
- Unique names cost linear time (UniqueNames) with the same names as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6c734777e01476881a3f34b3188571cc3f7150ab)
This commit is contained in:
1 parent
13c2ac321c
commit
b253cac8d4
25 files changed
+777
-173
No files matched your search
@@ -178,6 +178,7 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
public void TemplatesAreCheckedAsTheArchiveSettingsAre()
|
||||
{
|
||||
Assert.Null(new RenameTemplates("{year}/{title}", "{date}_{n}", "{title} 2026").Problem());
|
||||
Assert.Null(new RenameTemplates(File: "{name}.{ext}", Title: "Paris: {title}?").Problem());
|
||||
Assert.Equal("folderTemplate", new RenameTemplates(Folder: " ").Problem());
|
||||
Assert.Equal("fileTemplate", new RenameTemplates(File: "{nope}").Problem());
|
||||
Assert.Equal("fileTemplate", new RenameTemplates(File: "{date:%}").Problem());
|
||||
@@ -185,6 +186,198 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
Assert.True(new RenameTemplates().IsEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("{n}{ext}", "fileTemplate", "Extension")]
|
||||
[Case("{date}_{n}_{ext}", "fileTemplate", "Extension")]
|
||||
[Case("{title}", "fileTemplate", "NotUnique")]
|
||||
[Case("{date}_{hm}", "fileTemplate", "NotUnique")]
|
||||
[Case("{year}/{n}", "fileTemplate", "FileSeparator")]
|
||||
[Case("Originals/{date:yyyy}/{title}", "folderTemplate", "ReservedFolder")]
|
||||
[Case("{year}/exports", "folderTemplate", "ReservedFolder")]
|
||||
[Case(".archive/{date}", "folderTemplate", "ReservedFolder")]
|
||||
[Case("{date:.yyyy}", "folderTemplate", "ReservedFolder")]
|
||||
public void TemplatesThatWouldLoseOrHidePhotosAreRefused(string template, string field, string rule)
|
||||
{
|
||||
var folder = field == "folderTemplate";
|
||||
var templates = folder ? new RenameTemplates(Folder: template) : new RenameTemplates(File: template);
|
||||
Assert.Equal(field, templates.Problem());
|
||||
Assert.Equal(rule, folder ? TemplateRules.FolderRule(PathTemplate.Parse(template)) : TemplateRules.FileRule(PathTemplate.Parse(template)));
|
||||
}
|
||||
|
||||
/// <summary>A sidecar of <paramref name="files"/>, each photo's first capture time <paramref name="first"/> (none when null), titled <paramref name="title"/>.</summary>
|
||||
private static RenameSubject Filed(string folder, string? title, DateTime? first, params string[] files)
|
||||
{
|
||||
var manifest = Sequence(files) with { Title = title, Created = new DateTimeOffset(2026, 10, 1, 9, 30, 0, TimeSpan.Zero) };
|
||||
manifest = manifest with { Frames = [.. manifest.Frames.Select(f => f with { CapturedAt = first?.AddSeconds(10 * f.I) })] };
|
||||
return new RenameSubject(manifest.Id, folder, title, first, "Canon", "Canon EOS R5", null)
|
||||
{
|
||||
Files = new SequenceFiles(manifest, [.. manifest.Frames.Select(f => f.File)]),
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("{year}/{date} {ext}", "2026/2026-09-28 CR2", "2026/2026-09-28 JPG")]
|
||||
[Case("{date} {name}", "2026-09-28 IMG_0001", "2026-09-28 IMG_0001 (2)")]
|
||||
[Case("{year}/{date} {camera} {iso}", "2026/2026-09-28 Canon EOS R5", "2026/2026-09-28 Canon EOS R5 (2)")]
|
||||
public void FoldersFiledFromTheFirstPhotoStayWhereFilingPutThem(string template, string raw, string jpeg)
|
||||
{
|
||||
// RAW and JPEG of one day, filed by the template from their first photo ({ext}, {name}… are that photo's).
|
||||
RenameSubject[] subjects =
|
||||
[
|
||||
Filed(raw, null, Start, "originals/2026-09-28_0001.CR2", "originals/2026-09-28_0002.CR2"),
|
||||
Filed(jpeg, null, Start, "originals/2026-09-28_0001.JPG", "originals/2026-09-28_0002.JPG"),
|
||||
];
|
||||
var folders = subjects.Select(s => s.Folder).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), subjects, template, null, folders, folders.Contains).Steps);
|
||||
// The context filing saw: the folder each first frame gives.
|
||||
var context = FrameNaming.Context(subjects[0].Files!.Manifest.Frames[0], subjects[0].Files!.Manifest, null);
|
||||
Assert.Equal(raw.Replace(" (2)", string.Empty, StringComparison.Ordinal), PathTemplate.Parse(template).ExpandFolder(context));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASequenceWithoutACaptureTimeNeverTakesTodaysDate()
|
||||
{
|
||||
// No time in the sidecar: the day the sequence was made, as its files are named; no sidecar and no time: no move.
|
||||
var timeless = Filed("inbox/a", null, null, "originals/a.JPG");
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), [timeless], "{date}", null, ["inbox/a"], _ => false);
|
||||
Assert.Equal("2026-10-01", plan.Steps.Single().ToFolder);
|
||||
var row = new RenameSubject(Guid.NewGuid(), "inbox/b", "B", null, null, null, null);
|
||||
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), [row], "{date}", "{title} {date}", ["inbox/b"], _ => false).Steps);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASequenceWhoseSidecarCannotBeReadStaysAsItIsAndSoDoesTheFolderAroundIt()
|
||||
{
|
||||
var a = Filed("a", "A", Start, "originals/a.JPG");
|
||||
// Unreadable, titled as D: had it been planned, D would get " (2)".
|
||||
var unreadable = new RenameSubject(Guid.NewGuid(), "u", "D", Start, null, null, null) { Unreadable = true };
|
||||
var carrier = Filed("c", "C", Start, "originals/c.JPG");
|
||||
var inner = new RenameSubject(Guid.NewGuid(), "c/n", "N", Start, null, null, null) { Unreadable = true };
|
||||
var d = Filed("d", "D", Start, "originals/d.JPG");
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), [a, unreadable, carrier, d], "moved/{title}", "{title} 2026", ["a", "u", "c", "c/n", "d"], _ => false,
|
||||
[inner]);
|
||||
var steps = plan.Steps.ToDictionary(s => s.SequenceId);
|
||||
Assert.Equal(("moved/A 2026", "A 2026"), (steps[a.SequenceId].ToFolder, steps[a.SequenceId].ToTitle));
|
||||
Assert.Equal(("moved/D 2026", "D 2026"), (steps[d.SequenceId].ToFolder, steps[d.SequenceId].ToTitle));
|
||||
foreach (var kept in new[] { unreadable, inner })
|
||||
{
|
||||
var step = steps[kept.SequenceId];
|
||||
Assert.Equal((kept.Folder, kept.Title), (step.ToFolder, step.ToTitle));
|
||||
Assert.False(step.Changes);
|
||||
Assert.Equal(RenameBlock.Unreadable, step.Blocked.Single().Reason);
|
||||
}
|
||||
// Its own sidecar reads: the title changes, the folder cannot take the sequence inside along.
|
||||
Assert.Equal(("c", "C 2026"), (steps[carrier.SequenceId].ToFolder, steps[carrier.SequenceId].ToTitle));
|
||||
Assert.False(steps[inner.SequenceId].Carried);
|
||||
|
||||
// With a file template, a sequence without its sidecar's files stays too.
|
||||
var noFiles = new RenameSubject(Guid.NewGuid(), "x", "X", Start, null, null, null);
|
||||
var files = RenamePlanner.Plan(Guid.NewGuid(), [noFiles], "moved/{title}", null, ["x"], _ => false, fileTemplate: "{n}");
|
||||
Assert.Equal(("x", false), (files.Steps.Single().ToFolder, files.Steps.Single().Changes));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFolderATitleWouldHideFromScansIsEscapedAndFound()
|
||||
{
|
||||
var archive = new ArchivePaths(context.CreateTempDirectory("archive"));
|
||||
var originals = archive.FromRelative("inbox/a/originals");
|
||||
Directory.CreateDirectory(originals);
|
||||
File.WriteAllBytes(Path.Combine(originals, "IMG_0001.JPG"), TestPhotos.Jpeg(Start, 1));
|
||||
var subject = new RenameSubject(Guid.NewGuid(), "inbox/a", "Exports", Start, null, null, null);
|
||||
var step = RenamePlanner.Plan(Guid.NewGuid(), [subject], "{year}/{title}", null, ["inbox/a"], _ => false).Steps.Single();
|
||||
Assert.Equal("2026/_Exports", step.ToFolder);
|
||||
RenamePlanner.MoveFolder(archive, step);
|
||||
Assert.SequenceEqual(["2026/_Exports"], ArchiveScanner.FindSequenceFolders(archive).Select(f => f.RelativeFolder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TitlesKeepWhatAFileNameCannotHold()
|
||||
{
|
||||
var paris = new RenameSubject(Guid.NewGuid(), "s/paris", "Paris: night", Start, null, null, null);
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), [paris], "{title}", "{title} 2026", ["s/paris"], _ => false);
|
||||
// The title is text; the folder it names is a file name.
|
||||
Assert.Equal(("Paris: night 2026", "Paris_ night 2026"), (plan.Steps.Single().ToTitle, plan.Steps.Single().ToFolder));
|
||||
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), [paris with { Folder = "Paris_ night" }], "{title}", "{title}", ["Paris_ night"], _ => false).Steps);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TwoFoldersThatDifferOnlyInCaseAreNeverGivenOneFolder()
|
||||
{
|
||||
// A case-sensitive server: "trip (2)" and "TRIP (2)" are two folders, both of which "Trip (2)" would keep.
|
||||
RenameSubject At(string folder) => new(Guid.NewGuid(), folder, "Trip", Start, null, null, null);
|
||||
RenameSubject[] subjects = [At("trip (2)"), At("TRIP (2)")];
|
||||
var onDisk = new HashSet<string>(["trip (2)", "TRIP (2)"], StringComparer.Ordinal);
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), subjects, "{title}", null, onDisk, onDisk.Contains);
|
||||
var targets = plan.Steps.Select(s => s.ToFolder).ToList();
|
||||
Assert.SequenceEqual(["Trip (2)", "Trip"], targets);
|
||||
|
||||
// Where they went, the same template changes nothing.
|
||||
RenameSubject[] after = [.. subjects.Zip(targets, (s, t) => s with { Folder = t })];
|
||||
var moved = new HashSet<string>(targets, StringComparer.Ordinal);
|
||||
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), after, "{title}", null, moved, moved.Contains).Steps);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACaseOnlyMoveOntoAnotherFolderIsRefused()
|
||||
{
|
||||
var archive = new ArchivePaths(context.CreateTempDirectory("archive"));
|
||||
Directory.CreateDirectory(archive.FromRelative("trip (2)"));
|
||||
File.WriteAllText(Path.Combine(archive.FromRelative("trip (2)"), "a.txt"), "a");
|
||||
var step = new RenameStep(Guid.NewGuid(), "trip (2)", "Trip (2)", "Trip", "Trip");
|
||||
if (Directory.Exists(archive.FromRelative("TRIP (2)")))
|
||||
{
|
||||
// Case-insensitive: the folder takes the new case, and the step repeated finds it done.
|
||||
RenamePlanner.MoveFolder(archive, step);
|
||||
RenamePlanner.MoveFolder(archive, step);
|
||||
Assert.SequenceEqual(["Trip (2)"], Directory.EnumerateDirectories(archive.Root).Select(Path.GetFileName));
|
||||
Assert.Equal("a", File.ReadAllText(Path.Combine(archive.FromRelative("Trip (2)"), "a.txt")));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case-sensitive: another folder holds the new name exactly; neither moves.
|
||||
Directory.CreateDirectory(archive.FromRelative("Trip (2)"));
|
||||
Assert.Throws<IOException>(() => RenamePlanner.MoveFolder(archive, step));
|
||||
Assert.Equal("a", File.ReadAllText(Path.Combine(archive.FromRelative("trip (2)"), "a.txt")));
|
||||
Assert.Empty(Directory.EnumerateFileSystemEntries(archive.FromRelative("Trip (2)")));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionsAPhotoLostComeBackFromItsName()
|
||||
{
|
||||
var manifest = Sequence("originals/0001CR3", "originals/0002.CR3");
|
||||
manifest = manifest with { Frames = [.. manifest.Frames.Select(f => f with { Original = $"IMG_{f.I + 1:0000}.CR3" })] };
|
||||
Assert.Equal("CR3", FrameNaming.Context(manifest.Frames[0], manifest, null).Extension);
|
||||
Assert.SequenceEqual(["originals/0001CR3>originals/0001.CR3"], Plan(manifest, "{n:0000}").Moves.Select(m => $"{m.From}>{m.To}"));
|
||||
// A file that has an extension of a photo keeps that one, whatever the card's name said.
|
||||
Assert.Equal("CR3", FrameNaming.Context(manifest.Frames[1] with { Original = "IMG_0002.JPG" }, manifest, null).Extension);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManyPhotosOfOneNameAreNamedInLinearTimeAsTheSearchFromTwoNamesThem()
|
||||
{
|
||||
// Against the search from _2 it replaces, with names taken by stray files and companions in the way.
|
||||
var taken = new HashSet<string>(["a/x.JPG", "a/x_3.JPG", "a/x_4.xmp"], StringComparer.OrdinalIgnoreCase);
|
||||
var reference = new HashSet<string>(taken, StringComparer.OrdinalIgnoreCase);
|
||||
var names = new UniqueNames(taken);
|
||||
for (var i = 0; i < 12; i++)
|
||||
{
|
||||
// Every third photo has an XMP companion: "x_4" is free for the others, not for it.
|
||||
Func<string, bool> companion = i % 3 == 1 ? c => !reference.Contains(Path.ChangeExtension(c, ".xmp")) : _ => true;
|
||||
var expected = FrameNaming.Unique("a/x.JPG", c => !reference.Contains(c) && companion(c));
|
||||
reference.Add(expected);
|
||||
Assert.Equal(expected, names.Claim("a/x.JPG", companion), $"photo {i}");
|
||||
}
|
||||
|
||||
var frames = Enumerable.Range(0, 20_000).Select(i => $"originals/{i:00000}.JPG").ToArray();
|
||||
var manifest = Sequence(frames);
|
||||
var clock = System.Diagnostics.Stopwatch.StartNew();
|
||||
var plan = Plan(manifest, "{title}", title: "Sunset");
|
||||
Assert.True(clock.Elapsed.TotalSeconds < TestTiming.Budget(5), $"{clock.Elapsed.TotalSeconds:0.0} s");
|
||||
Assert.SequenceEqual(["originals/Sunset.JPG", "originals/Sunset_2.JPG", "originals/Sunset_3.JPG"], plan.Samples.Select(s => s.To));
|
||||
Assert.Equal("originals/Sunset_20000.JPG", plan.Moves[^1].To);
|
||||
}
|
||||
|
||||
private SequencePaths Folder(out ArchivePaths archive)
|
||||
{
|
||||
archive = new ArchivePaths(context.CreateTempDirectory("archive"));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Chronos.Core.Tests.Archiving;
|
||||
internal static class TestPhotos
|
||||
{
|
||||
public static byte[] Jpeg(DateTime captured, int seed, string make = "Canon", string model = "Canon EOS R5", string? serial = "0431",
|
||||
int width = 48, int height = 32, int orientation = 1)
|
||||
int width = 48, int height = 32, int orientation = 1, string? lens = null)
|
||||
{
|
||||
using var image = new ImageBuffer(width, height);
|
||||
var random = new Random(seed);
|
||||
@@ -28,14 +28,16 @@ internal static class TestPhotos
|
||||
FNumber = 8,
|
||||
Iso = 100,
|
||||
Orientation = orientation,
|
||||
LensModel = lens,
|
||||
});
|
||||
return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 85, App1Segments = [exif[4..]] });
|
||||
}
|
||||
|
||||
public static string Write(string path, DateTime captured, int seed, string make = "Canon", string model = "Canon EOS R5", string? serial = "0431")
|
||||
public static string Write(string path, DateTime captured, int seed, string make = "Canon", string model = "Canon EOS R5", string? serial = "0431",
|
||||
string? lens = null)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
File.WriteAllBytes(path, Jpeg(captured, seed, make, model, serial));
|
||||
File.WriteAllBytes(path, Jpeg(captured, seed, make, model, serial, lens: lens));
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,4 +113,46 @@ public sealed class FrameNamingTests(TestContext context)
|
||||
Assert.SequenceEqual(session.Items.Select(i => i.FileName),
|
||||
manifest.Frames.Select(f => PathTemplate.Parse(fileTemplate).ExpandFile(FrameNaming.Context(f, manifest, session.Title))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ALensChangedDuringASessionNamesItsPhotosAsTheirSequenceDoes()
|
||||
{
|
||||
var card = context.CreateTempDirectory("card");
|
||||
var folder = Path.Combine(card, "DCIM", "100CANON");
|
||||
for (var i = 0; i < 4; i++)
|
||||
TestPhotos.Write(Path.Combine(folder, $"IMG_{i + 1:0000}.JPG"), Start.AddSeconds(10 * i), i + 1, lens: i < 2 ? "RF15-35mm" : "RF24-70mm");
|
||||
const string fileTemplate = "{lens}_{n:0000}";
|
||||
var plan = await PlanAsync(card, context.CreateTempDirectory("archive"), new ImportOptions { FileTemplate = fileTemplate });
|
||||
var session = plan.Sessions.Single();
|
||||
// The sequence carries the lens of its first photo, which names every photo of it.
|
||||
Assert.SequenceEqual(["RF15-35mm_0001.JPG", "RF15-35mm_0002.JPG", "RF15-35mm_0003.JPG", "RF15-35mm_0004.JPG"], session.Items.Select(i => i.FileName));
|
||||
|
||||
var frames = session.Items.Select(item => SequenceFrames.FromMetadata(Guid.NewGuid(), "originals/" + item.FileName, Path.GetFileName(item.SourcePath),
|
||||
item.Size, new string('c', 64), MetadataReader.Read(Path.Combine(card, item.SourcePath)), item.CapturedAt)).ToList();
|
||||
var manifest = SequenceFrames.Insert(new SequenceManifest
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Camera = new SidecarCamera { Make = "Canon", Model = "Canon EOS R5" },
|
||||
Lens = "RF15-35mm",
|
||||
}, frames);
|
||||
Assert.Empty(FileRenames.Plan(manifest, session.Title, PathTemplate.Parse(fileTemplate), [.. manifest.Frames.Select(f => f.File)]).Moves);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUploadIsNamedWithItsSequencesCameraAsReorganizeNamesIt()
|
||||
{
|
||||
// The creator's hint stands for the camera the photos do not name; a second body's photo takes the sequence's camera.
|
||||
var start = new DateTime(2026, 9, 28, 18, 2, 11);
|
||||
var frames = new[] { Metadata(start), Metadata(start.AddSeconds(5)) with { Make = "GoPro", Model = "HERO12 Black", LensModel = null } }
|
||||
.Select((m, i) => SequenceFrames.FromMetadata(Guid.NewGuid(), $"IMG_{i}.JPG", $"IMG_{i}.JPG", 100, new string('a', 64), m)).ToList();
|
||||
var manifest = SequenceFrames.Insert(new SequenceManifest
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Camera = new SidecarCamera { Model = "Hinted body" },
|
||||
Lens = "RF15-35mm F2.8 L IS USM",
|
||||
}, frames);
|
||||
var template = PathTemplate.Parse("{camera}_{lens}_{n:00}");
|
||||
Assert.SequenceEqual(["Hinted body_RF15-35mm F2.8 L IS USM_01.JPG", "Hinted body_RF15-35mm F2.8 L IS USM_02.JPG"],
|
||||
manifest.Frames.Select(f => template.ExpandFile(FrameNaming.Context(f, manifest, null))));
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,57 @@ public sealed class PathTemplateTests
|
||||
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));
|
||||
}
|
||||
|
||||
[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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user