From 26b60d88b6d848f3ba55ca046852e079be5fe3c6 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 5 Nov 2023 22:11:26 +1100 Subject: Add SCI_SELECTIONFROMPOINT for modifying multiple selections. --- test/simpleTests.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/simpleTests.py b/test/simpleTests.py index fd1f7423a..4263ad036 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -809,11 +809,44 @@ class TestSimple(unittest.TestCase): self.assertEqual(self.ed.TargetEndVirtualSpace, 0) def testPointsAndPositions(self): - self.ed.AddText(1, b"x") + self.ed.SetContents(b"xyz") + + # Inter-character positions # Start of text - self.assertEqual(self.ed.PositionFromPoint(0,0), 0) + self.assertEqual(self.ed.PositionFromPoint(1,1), 0) # End of text - self.assertEqual(self.ed.PositionFromPoint(0,100), 1) + self.assertEqual(self.ed.PositionFromPoint(100, 1), 3) + self.assertEqual(self.ed.PositionFromPointClose(100, 1), -1) + + # Character positions + # Start of text + self.assertEqual(self.ed.CharPositionFromPoint(0,0), 0) + # End of text + self.assertEqual(self.ed.CharPositionFromPoint(100, 0), 3) + self.assertEqual(self.ed.CharPositionFromPointClose(100, 0), -1) + + def testSelectionFromPoint(self): + self.ed.SetContents(b"xxxxxx") + self.ed.SetSelection(3, 2) + self.ed.AddSelection(0, 1) + self.ed.AddSelection(5, 5) # Empty + xStart = self.ed.PointXFromPosition(0, 0) + xEnd = self.ed.PointXFromPosition(0, 5) + width = xEnd-xStart + charWidth = width // 5 + widthMid = charWidth // 2 + + posMid1 = xStart+widthMid + self.assertEqual(self.ed.SelectionFromPoint(posMid1, 1), 1) + posMid2 = xStart+charWidth+widthMid + self.assertEqual(self.ed.SelectionFromPoint(posMid2, 1), -1) + posMid3 = xStart+charWidth*2+widthMid + self.assertEqual(self.ed.SelectionFromPoint(posMid3, 1), 0) + # Empty selection at 5. Exact and then a few pixels either side + self.assertEqual(self.ed.SelectionFromPoint(xEnd, 1), 2) + self.assertEqual(self.ed.SelectionFromPoint(xEnd-2, 1), 2) + self.assertEqual(self.ed.SelectionFromPoint(xEnd+2, 1), 2) + self.assertEqual(self.ed.SelectionFromPoint(100, 0), -1) def testLinePositions(self): text = b"ab\ncd\nef" -- cgit v1.2.3