testvbscript_regexp.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import unittest
  2. from win32com.client.gencache import EnsureDispatch
  3. from win32com.client.dynamic import DumbDispatch
  4. import win32com.test.util
  5. class RegexTest(win32com.test.util.TestCase):
  6. def _CheckMatches(self, match, expected):
  7. found = []
  8. for imatch in match:
  9. found.append(imatch.FirstIndex)
  10. self.assertEquals(list(found), list(expected))
  11. def _TestVBScriptRegex(self, re):
  12. StringToSearch = "Python python pYthon Python"
  13. re.Pattern = "Python"
  14. re.Global = True
  15. re.IgnoreCase = True
  16. match = re.Execute(StringToSearch)
  17. expected = 0, 7, 14, 21
  18. self._CheckMatches(match, expected)
  19. re.IgnoreCase = False
  20. match = re.Execute(StringToSearch)
  21. expected = 0, 21
  22. self._CheckMatches(match, expected)
  23. def testDynamic(self):
  24. re = DumbDispatch("VBScript.Regexp")
  25. self._TestVBScriptRegex(re)
  26. def testGenerated(self):
  27. re = EnsureDispatch("VBScript.Regexp")
  28. self._TestVBScriptRegex(re)
  29. if __name__=='__main__':
  30. unittest.main()