150 行
6.0 KiB
C#
150 行
6.0 KiB
C#
using YukkuriMovieMaker.Plugin;
|
|
using YukkuriMovieMaker.Project;
|
|
|
|
namespace UndoTree.Tests;
|
|
|
|
[Collection("Settings")]
|
|
public sealed class UndoTreeExportTests
|
|
{
|
|
static UndoTreeRecordNode Node(int id, int parent, string label, string tag = "", bool saved = false, params UndoTreeRecordCommand[] commands)
|
|
=> new(id, parent, label, new DateTime(2026, 11, 1, 9, 30, 15), commands, tag, saved);
|
|
|
|
static string[] Lines(string text) => text.Split(Environment.NewLine);
|
|
|
|
[Fact]
|
|
public void TheMainLineIsFlatAndOtherBranchesAreNestedUnderTheirOwnHeading()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [
|
|
new UndoTreeRecordNode(1, -1, string.Empty, DateTime.MinValue, []),
|
|
Node(2, 1, "Document / X", "start", true, new UndoTreeRecordCommand("Property", "Document", "X", "0 → 1")),
|
|
Node(3, 2, "Document / Y"),
|
|
Node(4, 2, "Part / Value"),
|
|
]);
|
|
|
|
var text = UndoTreeExport.ToMarkdown(record, @"C:\work\a.ymmp");
|
|
|
|
Assert.Equal(
|
|
[
|
|
$"# {Texts.UndoTree}",
|
|
string.Empty,
|
|
@"C:\work\a.ymmp",
|
|
string.Empty,
|
|
$"- {Texts.InitialState}",
|
|
$"- [{Texts.SavedMark}][start] Document / X ({new DateTime(2026, 11, 1, 9, 30, 15):T})",
|
|
" - Document / X: 0 → 1",
|
|
$" - {Texts.SideBranches}",
|
|
$" - Document / Y ({new DateTime(2026, 11, 1, 9, 30, 15):T})",
|
|
$"- Part / Value ({new DateTime(2026, 11, 1, 9, 30, 15):T})",
|
|
string.Empty,
|
|
],
|
|
Lines(text));
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutAProjectThePathLineIsLeftOutAndAListChangeShowsItsText()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [
|
|
new UndoTreeRecordNode(0, -1, string.Empty, DateTime.MinValue, []),
|
|
Node(1, 0, "a", commands: new UndoTreeRecordCommand("ListItems", string.Empty, "Added 1 item(s)", string.Empty)),
|
|
]);
|
|
|
|
var text = UndoTreeExport.ToMarkdown(record, null);
|
|
|
|
Assert.Equal([$"# {Texts.UndoTree}", string.Empty, $"- {Texts.InitialState}"], Lines(text).Take(3));
|
|
Assert.Contains(" - Added 1 item(s)", Lines(text));
|
|
}
|
|
|
|
[Fact]
|
|
public void ALongLinearHistoryDoesNotGrowDeeperWithEveryStep()
|
|
{
|
|
var nodes = new List<UndoTreeRecordNode> { new(0, -1, string.Empty, DateTime.MinValue, []) };
|
|
nodes.AddRange(Enumerable.Range(1, 200).Select(id => Node(id, id - 1, "step " + id)));
|
|
|
|
var lines = Lines(UndoTreeExport.ToMarkdown(new UndoTreeRecord(DateTime.Now, nodes), null));
|
|
|
|
Assert.All(lines.Where(line => line.Length > 0 && line[0] != '#'), line => Assert.StartsWith("- ", line));
|
|
Assert.Equal(201, lines.Count(line => line.StartsWith("- ")));
|
|
}
|
|
|
|
[Fact]
|
|
public void ABranchKeepsItsOwnMainLineFlatAndTheMainLineContinuesAfterIt()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [
|
|
new UndoTreeRecordNode(0, -1, string.Empty, DateTime.MinValue, []),
|
|
new UndoTreeRecordNode(1, 0, "a", DateTime.MinValue, []),
|
|
new UndoTreeRecordNode(2, 1, "branch 1", DateTime.MinValue, []),
|
|
new UndoTreeRecordNode(3, 2, "branch 2", DateTime.MinValue, []),
|
|
new UndoTreeRecordNode(4, 1, "b", DateTime.MinValue, []),
|
|
new UndoTreeRecordNode(5, 4, "c", DateTime.MinValue, []),
|
|
]);
|
|
|
|
var lines = Lines(UndoTreeExport.ToMarkdown(record, null)).Skip(2).Where(line => line.Length > 0);
|
|
|
|
Assert.Equal(
|
|
[
|
|
$"- {Texts.InitialState}",
|
|
"- a",
|
|
$" - {Texts.SideBranches}",
|
|
" - branch 1",
|
|
" - branch 2",
|
|
"- b",
|
|
"- c",
|
|
],
|
|
lines);
|
|
}
|
|
|
|
[Fact]
|
|
public void LineBreaksInANameOrAValueNeverBreakTheList()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [
|
|
new UndoTreeRecordNode(0, -1, string.Empty, DateTime.MinValue, []),
|
|
Node(1, 0, "first\nsecond", commands: new UndoTreeRecordCommand("Property", "t", "m", "\"a\r\nb\" → \"c\"")),
|
|
]);
|
|
|
|
var lines = Lines(UndoTreeExport.ToMarkdown(record, null)).Where(line => line.Length > 0).Skip(2);
|
|
|
|
Assert.Equal([$"- first↵second ({new DateTime(2026, 11, 1, 9, 30, 15):T})", " - t / m: \"a↵b\" → \"c\""], lines);
|
|
}
|
|
|
|
[Fact]
|
|
public void AnOrphanedNodeStartsItsOwnTree()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [Node(5, 99, "orphan")]);
|
|
|
|
Assert.Contains(Lines(UndoTreeExport.ToMarkdown(record, null)), line => line.StartsWith("- orphan"));
|
|
}
|
|
|
|
[Fact]
|
|
public void TheViewModelTextFollowsTheLiveHistoryAndThenThePreviousOne()
|
|
{
|
|
var (manager, document) = Histories.NewDocument("p1");
|
|
var model = new UndoTreeViewModel();
|
|
Assert.Equal(string.Empty, model.HistoryText());
|
|
|
|
model.SetTimelineToolInfo(new TimelineToolInfo(null!, new Scenes(true), manager, new AsyncAwaitStatus()));
|
|
Histories.Edit(manager, () => document.X = 1);
|
|
|
|
Assert.Contains("- Document / X", model.HistoryText());
|
|
|
|
model.SetRecord(new UndoTreeRecord(DateTime.Now, [new UndoTreeRecordNode(0, -1, string.Empty, DateTime.MinValue, []), new UndoTreeRecordNode(1, 0, "last time", DateTime.MinValue, [])]));
|
|
model.IsShowingRecord = true;
|
|
|
|
Assert.Contains("- last time", model.HistoryText());
|
|
Assert.DoesNotContain("- Document / X", model.HistoryText());
|
|
}
|
|
|
|
[Fact]
|
|
public void TheExportCommandsAreAvailableOnlyWithAHistory()
|
|
{
|
|
var model = new UndoTreeViewModel();
|
|
Assert.False(model.CopyHistoryCommand.CanExecute(null));
|
|
Assert.False(model.ExportHistoryCommand.CanExecute(null));
|
|
|
|
var (manager, _) = Histories.NewDocument("p1");
|
|
model.SetTimelineToolInfo(new TimelineToolInfo(null!, new Scenes(true), manager, new AsyncAwaitStatus()));
|
|
|
|
Assert.True(model.CopyHistoryCommand.CanExecute(null));
|
|
Assert.True(model.ExportHistoryCommand.CanExecute(null));
|
|
}
|
|
}
|