示例#1
0
 public void Setup()
 {
     document      = new TextDocument();
     document.Text = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
     heightTree    = new HeightTree(document, 10);
     foreach (DocumentLine line in document.Lines)
     {
         heightTree.SetHeight(line, line.LineNumber);
     }
 }
示例#2
0
 public void TestHeightChanged()
 {
     heightTree.SetHeight(document.GetLineByNumber(4), 100);
     CheckHeights();
 }
        public void CollapsingTest()
        {
            char[]     chars      = { 'a', 'b', '\r', '\n' };
            char[]     buffer     = new char[20];
            HeightTree heightTree = new HeightTree(document, 10);
            List <CollapsedLineSection> collapsedSections = new List <CollapsedLineSection>();

            for (int i = 0; i < 2500; i++)
            {
//				Console.WriteLine("Iteration " + i);
//				Console.WriteLine(heightTree.GetTreeAsString());
//				foreach (CollapsedLineSection cs in collapsedSections) {
//					Console.WriteLine(cs);
//				}

                switch (rnd.Next(0, 10))
                {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    int offset        = rnd.Next(0, document.TextLength);
                    int length        = rnd.Next(0, document.TextLength - offset);
                    int newTextLength = rnd.Next(0, 20);
                    for (int j = 0; j < newTextLength; j++)
                    {
                        buffer[j] = chars[rnd.Next(0, chars.Length)];
                    }

                    document.Replace(offset, length, new string(buffer, 0, newTextLength));
                    break;

                case 6:
                case 7:
                    int startLine = rnd.Next(1, document.LineCount + 1);
                    int endLine   = rnd.Next(startLine, document.LineCount + 1);
                    collapsedSections.Add(heightTree.CollapseText(document.GetLineByNumber(startLine), document.GetLineByNumber(endLine)));
                    break;

                case 8:
                    if (collapsedSections.Count > 0)
                    {
                        CollapsedLineSection cs = collapsedSections[rnd.Next(0, collapsedSections.Count)];
                        // unless the text section containing the CollapsedSection was deleted:
                        if (cs.Start != null)
                        {
                            cs.Uncollapse();
                        }
                        collapsedSections.Remove(cs);
                    }
                    break;

                case 9:
                    foreach (DocumentLine ls in document.Lines)
                    {
                        heightTree.SetHeight(ls, ls.LineNumber);
                    }
                    break;
                }
                var treeSections  = new HashSet <CollapsedLineSection>(heightTree.GetAllCollapsedSections());
                int expectedCount = 0;
                foreach (CollapsedLineSection cs in collapsedSections)
                {
                    if (cs.Start != null)
                    {
                        expectedCount++;
                        Assert.IsTrue(treeSections.Contains(cs));
                    }
                }
                Assert.AreEqual(expectedCount, treeSections.Count);
                CheckLines();
                HeightTests.CheckHeights(document, heightTree);
            }
        }