aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2023-11-05 22:11:26 +1100
committerNeil <nyamatongwe@gmail.com>2023-11-05 22:11:26 +1100
commit26b60d88b6d848f3ba55ca046852e079be5fe3c6 (patch)
treebaf6523ea5e4f2d5adfb021def287a6858802b23 /test
parenta3dd1952c420158febe7a11d596ba3f402eb17ab (diff)
downloadscintilla-mirror-26b60d88b6d848f3ba55ca046852e079be5fe3c6.tar.gz
Add SCI_SELECTIONFROMPOINT for modifying multiple selections.
Diffstat (limited to 'test')
-rw-r--r--test/simpleTests.py39
1 files changed, 36 insertions, 3 deletions
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"