Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions ICSharpCode.AvalonEdit.Tests/Document/ChangeTrackingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System;
using System.Linq;

using NUnit.Framework;

namespace ICSharpCode.AvalonEdit.Document
Expand All @@ -31,12 +32,12 @@ public void NoChanges()
TextDocument document = new TextDocument("initial text");
ITextSource snapshot1 = document.CreateSnapshot();
ITextSource snapshot2 = document.CreateSnapshot();
Assert.AreEqual(0, snapshot1.Version.CompareAge(snapshot2.Version));
Assert.AreEqual(0, snapshot1.Version.GetChangesTo(snapshot2.Version).Count());
Assert.AreEqual(document.Text, snapshot1.Text);
Assert.AreEqual(document.Text, snapshot2.Text);
Assert.That(snapshot1.Version.CompareAge(snapshot2.Version), Is.EqualTo(0));
Assert.That(snapshot1.Version.GetChangesTo(snapshot2.Version).Count(), Is.EqualTo(0));
Assert.That(snapshot1.Text, Is.EqualTo(document.Text));
Assert.That(snapshot2.Text, Is.EqualTo(document.Text));
}

[Test]
public void ForwardChanges()
{
Expand All @@ -45,16 +46,16 @@ public void ForwardChanges()
document.Replace(0, 7, "nw");
document.Insert(1, "e");
ITextSource snapshot2 = document.CreateSnapshot();
Assert.AreEqual(-1, snapshot1.Version.CompareAge(snapshot2.Version));
Assert.That(snapshot1.Version.CompareAge(snapshot2.Version), Is.EqualTo(-1));
TextChangeEventArgs[] arr = snapshot1.Version.GetChangesTo(snapshot2.Version).ToArray();
Assert.AreEqual(2, arr.Length);
Assert.AreEqual("nw", arr[0].InsertedText.Text);
Assert.AreEqual("e", arr[1].InsertedText.Text);
Assert.AreEqual("initial text", snapshot1.Text);
Assert.AreEqual("new text", snapshot2.Text);
Assert.That(arr.Length, Is.EqualTo(2));
Assert.That(arr[0].InsertedText.Text, Is.EqualTo("nw"));
Assert.That(arr[1].InsertedText.Text, Is.EqualTo("e"));

Assert.That(snapshot1.Text, Is.EqualTo("initial text"));
Assert.That(snapshot2.Text, Is.EqualTo("new text"));
}

[Test]
public void BackwardChanges()
{
Expand All @@ -63,14 +64,14 @@ public void BackwardChanges()
document.Replace(0, 7, "nw");
document.Insert(1, "e");
ITextSource snapshot2 = document.CreateSnapshot();
Assert.AreEqual(1, snapshot2.Version.CompareAge(snapshot1.Version));
Assert.That(snapshot2.Version.CompareAge(snapshot1.Version), Is.EqualTo(1));
TextChangeEventArgs[] arr = snapshot2.Version.GetChangesTo(snapshot1.Version).ToArray();
Assert.AreEqual(2, arr.Length);
Assert.AreEqual("", arr[0].InsertedText.Text);
Assert.AreEqual("initial", arr[1].InsertedText.Text);
Assert.AreEqual("initial text", snapshot1.Text);
Assert.AreEqual("new text", snapshot2.Text);
Assert.That(arr.Length, Is.EqualTo(2));
Assert.That(arr[0].InsertedText.Text, Is.Empty);
Assert.That(arr[1].InsertedText.Text, Is.EqualTo("initial"));

Assert.That(snapshot1.Text, Is.EqualTo("initial text"));
Assert.That(snapshot2.Text, Is.EqualTo("new text"));
}
}
}
60 changes: 31 additions & 29 deletions ICSharpCode.AvalonEdit.Tests/Document/CollapsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
// DEALINGS IN THE SOFTWARE.

using System;

using ICSharpCode.AvalonEdit.Rendering;

using NUnit.Framework;

namespace ICSharpCode.AvalonEdit.Document
Expand All @@ -27,7 +29,7 @@ public class CollapsingTests
{
TextDocument document;
HeightTree heightTree;

[SetUp]
public void Setup()
{
Expand All @@ -38,40 +40,40 @@ public void Setup()
heightTree.SetHeight(line, line.LineNumber);
}
}

CollapsedLineSection SimpleCheck(int from, int to)
{
CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(from), document.GetLineByNumber(to));
for (int i = 1; i < from; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
for (int i = from; i <= to; i++) {
Assert.IsTrue(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.True);
}
for (int i = to + 1; i <= 10; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
return sec1;
}

[Test]
public void SimpleCheck()
{
SimpleCheck(4, 6);
}

[Test]
public void SimpleUncollapse()
{
CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(4), document.GetLineByNumber(6));
sec1.Uncollapse();
for (int i = 1; i <= 10; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
}

[Test]
public void FullCheck()
{
Expand All @@ -80,34 +82,34 @@ public void FullCheck()
try {
SimpleCheck(from, to).Uncollapse();
for (int i = 1; i <= 10; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
CheckHeights();
} catch {
Console.WriteLine("from = " + from + ", to = " + to);
throw;
}
}
}
}

[Test]
public void InsertInCollapsedSection()
{
CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(4), document.GetLineByNumber(6));
document.Insert(document.GetLineByNumber(5).Offset, "a\nb\nc");
for (int i = 1; i < 4; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
for (int i = 4; i <= 8; i++) {
Assert.IsTrue(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.True);
}
for (int i = 9; i <= 12; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
}

[Test]
public void RemoveInCollapsedSection()
{
Expand All @@ -116,17 +118,17 @@ public void RemoveInCollapsedSection()
int line6Offset = document.GetLineByNumber(6).Offset;
document.Remove(line4Offset, line6Offset - line4Offset);
for (int i = 1; i < 3; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
for (int i = 3; i <= 5; i++) {
Assert.IsTrue(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.True);
}
for (int i = 6; i <= 8; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
}

[Test]
public void RemoveEndOfCollapsedSection()
{
Expand All @@ -135,33 +137,33 @@ public void RemoveEndOfCollapsedSection()
int line8Offset = document.GetLineByNumber(8).Offset;
document.Remove(line5Offset, line8Offset - line5Offset);
for (int i = 1; i < 3; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
for (int i = 3; i <= 5; i++) {
Assert.IsTrue(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.True);
}
for (int i = 6; i <= 7; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
}

[Test]
public void RemoveCollapsedSection()
{
CollapsedLineSection sec1 = heightTree.CollapseText(document.GetLineByNumber(3), document.GetLineByNumber(3));
int line3Offset = document.GetLineByNumber(3).Offset;
document.Remove(line3Offset - 1, 1);
for (int i = 1; i <= 9; i++) {
Assert.IsFalse(heightTree.GetIsCollapsed(i));
Assert.That(heightTree.GetIsCollapsed(i), Is.False);
}
CheckHeights();
Assert.AreSame(null, sec1.Start);
Assert.AreSame(null, sec1.End);
Assert.That(sec1.Start, Is.SameAs(null));
Assert.That(sec1.End, Is.SameAs(null));
// section gets uncollapsed when it is removed
Assert.IsFalse(sec1.IsCollapsed);
Assert.That(sec1.IsCollapsed, Is.False);
}

void CheckHeights()
{
HeightTests.CheckHeights(document, heightTree);
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.AvalonEdit.Tests/Document/HeightTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ internal static void CheckHeights(TextDocument document, HeightTree heightTree)
visualPositions[i+1]=visualPositions[i]+heights[i];
}
foreach (DocumentLine ls in document.Lines) {
Assert.AreEqual(visualPositions[ls.LineNumber-1], heightTree.GetVisualPosition(ls));
Assert.That(heightTree.GetVisualPosition(ls), Is.EqualTo(visualPositions[ls.LineNumber - 1]));
}
Assert.AreEqual(visualPositions[document.LineCount], heightTree.TotalHeight);
Assert.That(heightTree.TotalHeight, Is.EqualTo(visualPositions[document.LineCount]));
}
}
}
Loading
Loading