diff options
author | Neil <nyamatongwe@gmail.com> | 2022-05-17 08:52:34 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-05-17 08:52:34 +1000 |
commit | 475450c76ceef43a7f5b2c68ed5848baee96b6dc (patch) | |
tree | 110ed93d9989eb049ecb0ee2c6fc62692adcefa0 /test | |
parent | e107ecdf3f5576e90dc90c69fc57f24d1f499b61 (diff) | |
download | scintilla-mirror-475450c76ceef43a7f5b2c68ed5848baee96b6dc.tar.gz |
Duplicate APIs to support 64-bit document positions on Win32:
SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL.
Diffstat (limited to 'test')
-rw-r--r-- | test/ScintillaCallable.py | 36 | ||||
-rw-r--r-- | test/simpleTests.py | 17 |
2 files changed, 53 insertions, 0 deletions
diff --git a/test/ScintillaCallable.py b/test/ScintillaCallable.py index 1164631ae..d8d16c7e3 100644 --- a/test/ScintillaCallable.py +++ b/test/ScintillaCallable.py @@ -21,6 +21,13 @@ class TEXTRANGE(ctypes.Structure): ('lpstrText', ctypes.POINTER(ctypes.c_char)), ) +class TEXTRANGEFULL(ctypes.Structure): + _fields_= (\ + ('cpMin', c_ssize_t), + ('cpMax', c_ssize_t), + ('lpstrText', ctypes.POINTER(ctypes.c_char)), + ) + class FINDTEXT(ctypes.Structure): _fields_= (\ ('cpMin', c_long), @@ -30,6 +37,15 @@ class FINDTEXT(ctypes.Structure): ('cpMaxText', c_long), ) +class FINDTEXTFULL(ctypes.Structure): + _fields_= (\ + ('cpMin', c_ssize_t), + ('cpMax', c_ssize_t), + ('lpstrText', c_char_p), + ('cpMinText', c_ssize_t), + ('cpMaxText', c_ssize_t), + ) + class SciCall: def __init__(self, fn, ptr, msg, stringResult=False): self._fn = fn @@ -136,6 +152,16 @@ class ScintillaCallable: text = tr.lpstrText[:length] text += b"\0" * (length - len(text)) return text + def ByteRangeFull(self, start, end): + tr = TEXTRANGEFULL() + tr.cpMin = start + tr.cpMax = end + length = end - start + tr.lpstrText = ctypes.create_string_buffer(length + 1) + self.GetTextRangeFull(0, ctypes.byref(tr)) + text = tr.lpstrText[:length] + text += b"\0" * (length - len(text)) + return text def StyledTextRange(self, start, end): tr = TEXTRANGE() tr.cpMin = start @@ -156,6 +182,16 @@ class ScintillaCallable: pos = self.FindText(flags, ctypes.byref(ft)) #~ print(start, end, ft.cpMinText, ft.cpMaxText) return pos + def FindBytesFull(self, start, end, s, flags): + ft = FINDTEXTFULL() + ft.cpMin = start + ft.cpMax = end + ft.lpstrText = s + ft.cpMinText = 0 + ft.cpMaxText = 0 + pos = self.FindTextFull(flags, ctypes.byref(ft)) + #~ print(start, end, ft.cpMinText, ft.cpMaxText) + return pos def Contents(self): return self.ByteRange(0, self.Length) diff --git a/test/simpleTests.py b/test/simpleTests.py index 7b326f8e0..195479eaa 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -165,6 +165,17 @@ class TestSimple(unittest.TestCase): self.assertEquals(self.ed.Length, 4) self.assertEquals(b"xxyy", self.ed.ByteRange(0,4)) + def testTextRangeFull(self): + data = b"xy" + self.ed.InsertText(0, data) + self.assertEquals(self.ed.Length, 2) + self.assertEquals(data, self.ed.ByteRangeFull(0,2)) + + self.ed.InsertText(1, data) + # Should now be "xxyy" + self.assertEquals(self.ed.Length, 4) + self.assertEquals(b"xxyy", self.ed.ByteRangeFull(0,4)) + def testInsertNul(self): data = b"\0" self.ed.AddText(1, data) @@ -1187,6 +1198,12 @@ class TestSearch(unittest.TestCase): pos = self.ed.FindBytes(0, self.ed.Length, b"big", 0) self.assertEquals(pos, 2) + def testFindFull(self): + pos = self.ed.FindBytesFull(0, self.ed.Length, b"zzz", 0) + self.assertEquals(pos, -1) + pos = self.ed.FindBytesFull(0, self.ed.Length, b"big", 0) + self.assertEquals(pos, 2) + def testFindEmpty(self): pos = self.ed.FindBytes(0, self.ed.Length, b"", 0) self.assertEquals(pos, 0) |