Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed May 24, 2024
1 parent e39b040 commit cb905bc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ def test_find(self):
if loc != -1:
self.assertEqual(i[loc:loc+len(j)], j)

# test tuple arguments
self.checkequal(2, '__aa__bb__', 'find', ('aa', 'bb'))
self.checkequal(2, '__aa__bb__', 'find', ('bb', 'aa'))
self.checkequal(-1, '__aa__bb__', 'find', ('cc', 'dd'))
self.checkequal(-1, '__aa__bb__', 'find', ())
self.checkequal(6, '__aa__bb__', 'find', ('aa', 'bb'), 3)
self.checkequal(-1, '__aa__bb__', 'find', ('aa', 'cc'), 3)
self.checkequal(2, '__aa__bb__', 'find', ('aa', 'bb'), 0, 10)
self.checkequal(-1, '__aa__bb__', 'find', ('aa', 'bb'), 0, 3)
self.checkequal(2, '__aa__bb__', 'find', ('aa', 'bb'), 0, 4)

self.checkraises(TypeError, 'hello', 'find', (42,))

def test_rfind(self):
self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc')
self.checkequal(12, 'abcdefghiabc', 'rfind', '')
Expand Down Expand Up @@ -270,6 +283,18 @@ def test_rfind(self):
# issue #15534
self.checkequal(0, '<......\u043c...', "rfind", "<")

# test tuple arguments
self.checkequal(6, '__aa__bb__', 'rfind', ('aa', 'bb'))
self.checkequal(6, '__aa__bb__', 'rfind', ('bb', 'aa'))
self.checkequal(-1, '__aa__bb__', 'rfind', ('cc', 'dd'))
self.checkequal(-1, '__aa__bb__', 'rfind', ())
self.checkequal(-1, '__aa__bb__', 'rfind', ('aa', 'cc'), 3)
self.checkequal(6, '__aa__bb__', 'rfind', ('aa', 'bb'), 0, 10)
self.checkequal(-1, '__aa__bb__', 'rfind', ('aa', 'bb'), 7, 10)
self.checkequal(6, '__aa__bb__', 'rfind', ('aa', 'bb'), 6, 10)

self.checkraises(TypeError, 'hello', 'rfind', (42,))

def test_index(self):
self.checkequal(0, 'abcdefghiabc', 'index', '')
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
Expand Down

0 comments on commit cb905bc

Please sign in to comment.