void CheckHeights()
 {
     HeightTests.CheckHeights(document, heightTree);
 }
Exemple #2
0
        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);
            }
        }