diff options
author | nyamatongwe <unknown> | 2010-03-25 12:10:59 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2010-03-25 12:10:59 +0000 |
commit | 295013083c4e9454656c0e94ab977057ee55ea11 (patch) | |
tree | 661dd867b477a189c846fada99399ba9a61bc191 /test/simpleTests.py | |
parent | 9f6eff4d795ec5cef078a432b89744f5542a1ade (diff) | |
download | scintilla-mirror-295013083c4e9454656c0e94ab977057ee55ea11.tar.gz |
New case insensitive searching implementation uses objects implementing
the CaseFolder interface to fold both search text and document text
so they can be compared with a simple strcmp.
A simple table based folder CaseFolderTable is used for 8 bit encodings
and maps input bytes to folded bytes. For multi-byte encodings
except for UTF-8 a null (output same as input) CaseFolderTable is used.
For UTF-8, more complex subclasses are used which call platform APIs
to perform the folding.
Folding is approximately to lower case although this differs between
platforms.
Diffstat (limited to 'test/simpleTests.py')
-rw-r--r-- | test/simpleTests.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/simpleTests.py b/test/simpleTests.py index f9a67f59b..8fac00cd4 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1109,6 +1109,84 @@ class TestCaseMapping(unittest.TestCase): self.assertEquals(self.ed.Length, 1) self.assertEquals(self.ed.Contents(), r) +class TestCaseInsensitiveSearch(unittest.TestCase): + def setUp(self): + self.xite = XiteWin.xiteFrame + self.ed = self.xite.ed + self.ed.ClearAll() + self.ed.EmptyUndoBuffer() + + def tearDown(self): + self.ed.SetCodePage(0) + self.ed.StyleSetCharacterSet(self.ed.STYLE_DEFAULT, self.ed.SC_CHARSET_DEFAULT) + + def testEmpty(self): + text = b" x X" + searchString = b"" + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(-1, pos) + + def testASCII(self): + text = b" x X" + searchString = b"X" + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(1, pos) + + def testLatin1(self): + text = "Frånd Åå".encode("Latin-1") + searchString = "Å".encode("Latin-1") + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(2, pos) + + def testRussian(self): + self.ed.StyleSetCharacterSet(self.ed.STYLE_DEFAULT, self.ed.SC_CHARSET_RUSSIAN) + text = "=(Б tex б)".encode("Windows-1251") + searchString = "б".encode("Windows-1251") + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(2, pos) + + def testUTF(self): + self.ed.SetCodePage(65001) + text = "Frånd Åå".encode("UTF-8") + searchString = "Å".encode("UTF-8") + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(2, pos) + + def testUTFDifferentLength(self): + # Searching for a two byte string "ı" finds a single byte "I" + self.ed.SetCodePage(65001) + text = "Fråndi Ååİ $".encode("UTF-8") + firstPosition = len("Frånd".encode("UTF-8")) + searchString = "İ".encode("UTF-8") + self.assertEquals(len(searchString), 2) + self.ed.SetText(len(text), text) + self.ed.TargetStart = 0 + self.ed.TargetEnd = self.ed.Length-1 + self.ed.SearchFlags = 0 + pos = self.ed.SearchInTarget(len(searchString), searchString) + self.assertEquals(firstPosition, pos) + self.assertEquals(firstPosition+1, self.ed.TargetEnd) + class TestLexer(unittest.TestCase): def setUp(self): self.xite = XiteWin.xiteFrame |