public void TestCoordinatesAfterFolding ()
		{
			var editor = new TextEditorData ();
			for (int i = 0; i < 100; i++)
				editor.Insert (0, "line\n");
			
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			
			heightTree.Fold (1, 2);
			
			heightTree.Fold (6, 4);
			heightTree.Fold (5, 10);
			
			var f = heightTree.Fold (20, 8);
			heightTree.Unfold (f, 20, 8);
			
			heightTree.Fold (20, 4);
			heightTree.Fold (25, 4);
			
			for (int i = 50; i <= editor.LineCount; i++) {
				var y = System.Math.Max (0, (i - 3 - 10 - 8) * editor.LineHeight);
				Assert.AreEqual (y, heightTree.LineNumberToY (i), "line:" + i + " --> y:" + y);
				Assert.AreEqual (i, heightTree.YToLineNumber (y), "y:" + y + " --> line:" + i);
			}
			for (int i = 50; i <= editor.LineCount; i++) {
				var y = System.Math.Max (0, (i - 3 - 10 - 8) * editor.LineHeight);
				Assert.AreEqual (y, heightTree.LineNumberToY (i), "line:" + i + " --> y:" + y);
				Assert.AreEqual (i, heightTree.YToLineNumber (y), "y:" + y + " --> line:" + i);
			}
		}
		public void TestYToLineNumberWithFolds ()
		{
			var editor = Create ("1\n2\n3\n4\n5\n6\n7\n8\n9\n0");
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			heightTree.Fold (1, 2);
			heightTree.Fold (6, 3);
			heightTree.Fold (5, 5);
			
			Assert.AreEqual (1, heightTree.YToLineNumber (0 * editor.LineHeight));
			Assert.AreEqual (4, heightTree.YToLineNumber (1 * editor.LineHeight));
			Assert.AreEqual (5, heightTree.YToLineNumber (2 * editor.LineHeight));
		}
示例#3
0
        public void TestSetLineHeight()
        {
            var editor = new TextEditorData();

            editor.Text = "1\n2\n3\n4\n5\n6\n7";
            HeightTree heightTree = new HeightTree(editor);

            heightTree.Rebuild();
            for (int i = 1; i <= editor.LineCount; i += 2)
            {
                heightTree.SetLineHeight(i, editor.LineHeight * 2);
            }

            double y = 0;

            for (int i = 1; i <= editor.LineCount; i++)
            {
                Assert.AreEqual(y, heightTree.LineNumberToY(i));
                y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2;
            }

            y = 0;
            for (int i = 1; i <= editor.LineCount; i++)
            {
                Assert.AreEqual(i, heightTree.YToLineNumber(y));
                y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2;
            }
        }
		public void TestFoldYToLineNumber ()
		{
			var editor = Create ("1\n2\n3\n4\n5\n6\n7");
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			
			heightTree.Fold (2, 2);
			
			for (int i = 1; i <= editor.LineCount; i++) {
				int j = i;
				if (j >= 2) {
					if (j <= 4) {
						j = 2;
					} else { 
						j -= 2;
					}
				}
				
				int k;
				if (i >= 2 && i <= 4) {
					k = 2;
				} else {
					k = i;
				}
				
				Assert.AreEqual (k, heightTree.YToLineNumber ((j - 1) * editor.LineHeight));
			}
		}
		public void TestSimpleYToLineNumber ()
		{
			var editor = Create ("1\n2\n3\n4\n5\n6\n7");
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			for (int i = 1; i <= editor.LineCount; i++) {
				Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight));
			}
		}
		public void TestUnfold ()
		{
			var editor = Create ("1\n2\n3\n4\n5\n6\n7");
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			var f = heightTree.Fold (2, 2);
			heightTree.Unfold (f, 2, 2);
			for (int i = 1; i <= editor.LineCount; i++) {
				Assert.AreEqual ((i - 1) * editor.LineHeight, heightTree.LineNumberToY (i));
				Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight));
			}
		}
示例#7
0
		public void TestSetLineHeight ()
		{
			var editor = new TextEditorData ();
			editor.Text = "1\n2\n3\n4\n5\n6\n7";
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			for (int i = 1; i <= editor.LineCount; i += 2) {
				heightTree.SetLineHeight (i, editor.LineHeight * 2);
			}
			
			double y = 0;
			for (int i = 1; i <= editor.LineCount; i++) {
				Assert.AreEqual (y, heightTree.LineNumberToY (i));
				y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2;
			}
			
			y = 0;
			for (int i = 1; i <= editor.LineCount; i++) {
				Assert.AreEqual (i, heightTree.YToLineNumber (y));
				y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2;
			}
			
		}
示例#8
0
		public void TestUnfold ()
		{
			var editor = new TextEditorData ();
			editor.Text = "1\n2\n3\n4\n5\n6\n7";
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			heightTree.Fold (2, 2);
			heightTree.Unfold (2, 2);
			for (int i = 1; i <= editor.LineCount; i++) {
				Assert.AreEqual ((i - 1) * editor.LineHeight, heightTree.LineNumberToY (i));
				Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight));
			}
		}
示例#9
0
		public void TestFoldYToLineNumber ()
		{
			var editor = new TextEditorData ();
			editor.Text = "1\n2\n3\n4\n5\n6\n7";
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			
			heightTree.Fold (2, 2);
			
			for (int i = 1; i <= editor.LineCount; i++) {
				int j = i;
				if (j >= 2) {
					if (j <= 4) {
						j = 2;
					} else { 
						j -= 2;
					}
				}
				
				int k;
				if (i >= 2 && i <= 4) {
					k = 2;
				} else {
					k = i;
				}
				
				Assert.AreEqual (k, heightTree.YToLineNumber ((j - 1) * editor.LineHeight));
			}
		}
示例#10
0
		public void TestCoordinatesAfterFolding ()
		{
			var editor = new TextEditorData ();
			for (int i = 0; i < 100; i++)
				editor.Insert (0, "line\n");
			
			HeightTree heightTree = new HeightTree (editor);
			heightTree.Rebuild ();
			
			heightTree.Fold (1, 2);
			
			heightTree.Fold (6, 4);
			heightTree.Fold (5, 10);
			
			var f = heightTree.Fold (20, 8);
			heightTree.Unfold (f, 20, 8);
			
			heightTree.Fold (20, 4);
			heightTree.Fold (25, 4);
			
			for (int i = 50; i <= editor.LineCount; i++) {
				var y = System.Math.Max (0, (i - 3 - 10 - 8) * editor.LineHeight);
				Assert.AreEqual (y, heightTree.LineNumberToY (i), "line:" + i + " --> y:" + y);
				Assert.AreEqual (i, heightTree.YToLineNumber (y), "y:" + y + " --> line:" + i);
			}
			for (int i = 50; i <= editor.LineCount; i++) {
				var y = System.Math.Max (0, (i - 3 - 10 - 8) * editor.LineHeight);
				Assert.AreEqual (y, heightTree.LineNumberToY (i), "line:" + i + " --> y:" + y);
				Assert.AreEqual (i, heightTree.YToLineNumber (y), "y:" + y + " --> line:" + i);
			}
		}