diff --git a/UndoTree.Tests/Documents.cs b/UndoTree.Tests/Documents.cs new file mode 100644 index 0000000..b3b18da --- /dev/null +++ b/UndoTree.Tests/Documents.cs @@ -0,0 +1,129 @@ +using System.Collections.Immutable; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations; +using YukkuriMovieMaker.UndoRedo; + +namespace UndoTree.Tests; + +public sealed class Part : UndoRedoable +{ + int value; + + public Part(string label) => Label = label; + + public string Label { get; } + + public int Value + { + get => value; + set => Set(ref this.value, value); + } + + public override string ToString() => $"{Label}:{Value}"; +} + +public sealed class Document : UndoRedoable +{ + int x; + int y; + + public Document() => SubscribeObservableCollectionChangedAndChild(Parts); + + public int X + { + get => x; + set => Set(ref x, value); + } + + public int Y + { + get => y; + set => Set(ref y, value); + } + + public ObservableCollection Parts { get; } = []; + + public string Snapshot() => $"X={X} Y={Y} Parts=[{string.Join(",", Parts)}]"; +} + +public sealed class Sheet : UndoRedoable +{ + ImmutableList parts = []; + int x; + + public int X + { + get => x; + set => Set(ref x, value); + } + + public ImmutableList Parts + { + get => parts; + set => Set(ref parts, value); + } + + public void Seed(ImmutableList seeded) => parts = seeded; + + public string Snapshot() => $"X={X} Parts=[{string.Join(",", Parts.Select(part => part.Label))}]"; +} + +public sealed class Group : UndoRedoable +{ + Document? child; + + public Document? Child + { + get => child; + set => Set(ref child, value); + } +} + +public sealed class Labelled : UndoRedoable +{ + int amount; + int broken; + + [Display(Name = "Visible name")] + public int Amount + { + get => amount; + set => Set(ref amount, value); + } + + [Display(Name = "Missing", ResourceType = typeof(Texts))] + public int Broken + { + get => broken; + set => Set(ref broken, value); + } +} + +public static class Histories +{ + public static (UndoRedoManager Manager, Document Document) NewDocument(params string[] partLabels) + { + var document = new Document(); + foreach (var label in partLabels) + document.Parts.Add(new Part(label)); + + var manager = new UndoRedoManager(); + manager.Subscribe(document); + return (manager, document); + } + + public static (UndoRedoManager Manager, Sheet Sheet) NewSheet(params string[] partLabels) + { + var sheet = new Sheet(); + sheet.Seed([.. partLabels.Select(label => new Part(label))]); + var manager = new UndoRedoManager(); + manager.Subscribe(sheet); + return (manager, sheet); + } + + public static void Edit(UndoRedoManager manager, Action change) + { + change(); + manager.Record(); + } +} diff --git a/UndoTree.Tests/UndoTree.Tests.csproj b/UndoTree.Tests/UndoTree.Tests.csproj index b5f6a7e..d2c2bfc 100644 --- a/UndoTree.Tests/UndoTree.Tests.csproj +++ b/UndoTree.Tests/UndoTree.Tests.csproj @@ -62,6 +62,10 @@ $(YMM4DirPath)Vortice.Mathematics.dll false + + $(YMM4DirPath)YukkuriMovieMaker.dll + false + $(YMM4DirPath)YukkuriMovieMaker.Controls.dll false