Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 internal CollapsedLineSection(HeightTree heightTree, DocumentLine start, DocumentLine end)
 {
     this.heightTree = heightTree;
     this.start      = start;
     this.end        = end;
                 #if DEBUG
     this.ID = "#" + (nextId++);
                 #endif
 }
Ejemplo n.º 3
0
 internal CollapsedLineSection(HeightTree heightTree, DocumentLine start, DocumentLine end)
 {
     this.heightTree = heightTree;
     this.start = start;
     this.end = end;
     #if DEBUG
     this.ID = "#" + (nextId++);
     #endif
 }
Ejemplo n.º 4
0
		internal CollapsedLineSection(HeightTree heightTree, DocumentLine start, DocumentLine end)
		{
			this.heightTree = heightTree;
			this.start = start;
			this.end = end;

			unchecked {
				this.ID = " #" + (nextId++);
			}

		}
Ejemplo n.º 5
0
 internal static void CheckHeights(TextDocument document, HeightTree heightTree)
 {
     double[] heights = document.Lines.Select(l => heightTree.GetIsCollapsed(l) ? 0 : heightTree.GetHeight(l)).ToArray();
     double[] visualPositions = new double[document.LineCount+1];
     for (int i = 0; i < heights.Length; i++) {
         visualPositions[i+1]=visualPositions[i]+heights[i];
     }
     foreach (DocumentLine ls in document.Lines) {
         Assert.AreEqual(visualPositions[ls.LineNumber-1], heightTree.GetVisualPosition(ls));
     }
     Assert.AreEqual(visualPositions[document.LineCount], heightTree.TotalHeight);
 }
		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);
			}
		}