48
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 unit tests for `textshaper.split`
|
|
6 """
|
|
7
|
|
8 # imports
|
|
9 import unittest
|
|
10 from textshaper import split
|
|
11
|
|
12
|
51
|
13
|
48
|
14 class SplitUnitTest(unittest.TestCase):
|
|
15
|
|
16 def test_findall(self):
|
51
|
17 """test finding all substrings"""
|
48
|
18
|
49
|
19 # 012345678901
|
|
20 string = 'a cat, a bat'
|
48
|
21
|
49
|
22 retval = split.findall(string, 'a')
|
50
|
23 self.assertEqual(retval, [0,3,7,10])
|
|
24
|
|
25 self.assertEqual(split.findall(string, 't'),
|
|
26 [4, 11])
|
|
27
|
51
|
28 def test_indices(self):
|
|
29 """test finding ordered indices"""
|
|
30 string = 'a cat, a bat'
|
|
31 indices = split.indices(string, ('a', 't'))
|
|
32 self.assertEqual(indices,
|
|
33 [(0, 'a'),
|
|
34 (3, 'a'),
|
|
35 (4, 't'),
|
|
36 (7, 'a'),
|
|
37 (10, 'a'),
|
|
38 (11, 't')])
|
|
39
|
50
|
40
|
48
|
41 if __name__ == '__main__':
|
|
42 unittest.main()
|
|
43
|