63 行
2.3 KiB
C#
63 行
2.3 KiB
C#
namespace UndoTree.Tests;
|
|
|
|
public sealed class UndoTreeTextTests
|
|
{
|
|
[Fact]
|
|
public void EveryKindOfLineBreakBecomesOneVisibleMark()
|
|
{
|
|
Assert.Equal("a↵b↵c↵d", UndoTreeText.SingleLine("a\r\nb\nc\rd"));
|
|
Assert.Equal("one line", UndoTreeText.SingleLine("one line"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ATextOfTheLimitIsKeptAndALongerOneIsCutWithAnEllipsis()
|
|
{
|
|
var limit = new string('a', UndoTreeText.MaxLength);
|
|
|
|
Assert.Equal(limit, UndoTreeText.Shorten(limit));
|
|
Assert.Equal(limit + "…", UndoTreeText.Shorten(limit + "b"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ACutNeverSplitsASurrogatePair()
|
|
{
|
|
var text = new string('a', UndoTreeText.MaxLength - 1) + "😀" + "bbb";
|
|
|
|
var shortened = UndoTreeText.Shorten(text);
|
|
|
|
Assert.Equal(new string('a', UndoTreeText.MaxLength - 1) + "…", shortened);
|
|
}
|
|
|
|
[Fact]
|
|
public void TheTextsAreJoinedTheSameWayEverywhere()
|
|
{
|
|
Assert.Equal("target / member", UndoTreeText.Join("target", "member"));
|
|
Assert.Equal("member", UndoTreeText.Join(string.Empty, "member"));
|
|
Assert.Equal("text: detail", UndoTreeText.WithDetail("text", "detail"));
|
|
Assert.Equal("text", UndoTreeText.WithDetail("text", string.Empty));
|
|
Assert.Equal("text — note", UndoTreeText.WithNote("text", "note"));
|
|
Assert.Equal("text", UndoTreeText.WithNote("text", string.Empty));
|
|
}
|
|
|
|
[Fact]
|
|
public void TheMarksComeInTheOrderBaseSavedTagBranches()
|
|
{
|
|
Assert.Equal($"[{Texts.BaseMark}][{Texts.SavedMark}][tag][branch]", UndoTreeText.Marks(true, true, "tag", "[branch]"));
|
|
Assert.Equal($"[{Texts.SavedMark}]", UndoTreeText.Marks(false, true, string.Empty, string.Empty));
|
|
Assert.Equal(string.Empty, UndoTreeText.Marks(false, false, string.Empty, string.Empty));
|
|
}
|
|
|
|
[Fact]
|
|
public void ALabelWithLineBreaksOrTooManyCharactersIsShownOnOneShortLine()
|
|
{
|
|
Assert.Equal("first↵second", UndoRedoCommandView.LabelOf(new Part("first\nsecond")));
|
|
Assert.Equal(new string('x', UndoTreeText.MaxLength) + "…", UndoRedoCommandView.LabelOf(new Part(new string('x', 100))));
|
|
}
|
|
|
|
[Fact]
|
|
public void AStringValueWithLineBreaksIsShownOnOneLine()
|
|
{
|
|
Assert.Equal("\"a↵b\"", UndoRedoCommandView.TextOf("a\nb"));
|
|
}
|
|
}
|