From a7a6886b727e722ef5d541be9ffe851ef81360e7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 26 Jul 2022 12:26:07 +0100 Subject: [PATCH] Proves that the ScrollTo and CursorPosition methods work as expected. --- UnitTests/TextViewTests.cs | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/UnitTests/TextViewTests.cs b/UnitTests/TextViewTests.cs index e5ab10cf5..35bf6d05d 100644 --- a/UnitTests/TextViewTests.cs +++ b/UnitTests/TextViewTests.cs @@ -5725,5 +5725,47 @@ line. tv.ProcessKey (new KeyEvent (Key.p, new KeyModifiers ())); } + + [Fact] + [AutoInitShutdown] + public void MoveDown_By_Setting_CursorPosition () + { + var tv = new TextView { + Width = 10, + Height = 5 + }; + + // add 100 lines of wide text to view + for (int i = 0; i < 100; i++) + tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine); + + Assert.Equal (new Point (0, 0), tv.CursorPosition); + tv.CursorPosition = new Point (5, 50); + Assert.Equal (new Point (5, 50), tv.CursorPosition); + + tv.CursorPosition = new Point (200, 200); + Assert.Equal (new Point (100, 99), tv.CursorPosition); + } + + [Fact] + [AutoInitShutdown] + public void ScrollTo_CursorPosition () + { + var tv = new TextView { + Width = 10, + Height = 5 + }; + + // add 100 lines of wide text to view + for (int i = 0; i < 100; i++) + tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine); + + Assert.Equal (new Point (0, 0), tv.CursorPosition); + tv.ScrollTo (50); + Assert.Equal (new Point (0, 0), tv.CursorPosition); + + tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow); + Assert.Equal (new Point (0, 50), tv.CursorPosition); + } } } \ No newline at end of file