59 行
2.1 KiB
C#
59 行
2.1 KiB
C#
namespace UndoTree.Tests;
|
|
|
|
public sealed class UndoTreeArchiveTests
|
|
{
|
|
static UndoTreeRecordNode Node(int id, int parent, string label, params UndoTreeRecordCommand[] commands)
|
|
=> new(id, parent, label, new DateTime(2026, 11, 1, 9, 0, 0), commands);
|
|
|
|
[Fact]
|
|
public void TheTreeIsRebuiltFromTheIdsAndParentsWhateverTheNumbering()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [Node(5, -1, string.Empty), Node(6, 5, "a"), Node(7, 6, "b"), Node(8, 6, "c")]);
|
|
|
|
var nodes = UndoTreeArchive.Restore(record);
|
|
|
|
Assert.Equal(4, nodes.Count);
|
|
var root = Assert.Single(nodes, node => node.IsRoot);
|
|
Assert.Equal(["a"], root.Children.Select(node => node.Label));
|
|
Assert.Equal(["b", "c"], root.Children[0].Children.Select(node => node.Label));
|
|
Assert.Equal(2, nodes[3].Depth);
|
|
}
|
|
|
|
[Fact]
|
|
public void EveryRestoredNodeIsReadOnlyAndLookedAtAsPartOfThePath()
|
|
{
|
|
var nodes = UndoTreeArchive.Restore(new UndoTreeRecord(DateTime.Now, [Node(0, -1, string.Empty), Node(1, 0, "a")]));
|
|
|
|
Assert.All(nodes, node =>
|
|
{
|
|
Assert.True(node.IsArchived);
|
|
Assert.True(node.IsOnPath);
|
|
Assert.Null(node.Handle);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void TheCommandsKeepTheirTextsAndAnUnknownKindBecomesOther()
|
|
{
|
|
var record = new UndoTreeRecord(DateTime.Now, [
|
|
Node(0, -1, string.Empty),
|
|
Node(1, 0, "a", new UndoTreeRecordCommand("Property", "Document", "X", "0 → 1"), new UndoTreeRecordCommand("Unknown", "t", "m", "d")),
|
|
]);
|
|
|
|
var commands = UndoTreeArchive.Restore(record)[1].Commands;
|
|
|
|
Assert.Equal([CommandKind.Property, CommandKind.Other], commands.Select(command => command.Kind));
|
|
Assert.Equal("Document / X", commands[0].Text);
|
|
Assert.Equal("0 → 1", commands[0].Detail);
|
|
Assert.All(commands, command => Assert.Null(command.Target));
|
|
}
|
|
|
|
[Fact]
|
|
public void ANodeWhoseParentIsMissingBecomesARoot()
|
|
{
|
|
var nodes = UndoTreeArchive.Restore(new UndoTreeRecord(DateTime.Now, [Node(1, 99, "orphan")]));
|
|
|
|
Assert.True(Assert.Single(nodes).IsRoot);
|
|
}
|
|
}
|