view tests/test_split.py @ 54:1d755747e67a

almost there
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 May 2015 09:11:30 -0700
parents c3b69728f291
children
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
unit tests for `textshaper.split`
"""

# imports
import unittest
from textshaper import split



class SplitUnitTest(unittest.TestCase):

    def test_findall(self):
        """test finding all substrings"""

                # 012345678901
        string = 'a cat, a bat'

        retval = split.findall(string, 'a')
        self.assertEqual(retval, [0,3,7,10])

        self.assertEqual(split.findall(string, 't'),
                         [4, 11])

    def test_indices(self):
        """test finding ordered indices"""
        string = 'a cat, a bat'
        indices = split.indices(string, ('a', 't'))
        self.assertEqual(indices,
                         [(0, 'a'),
                          (3, 'a'),
                          (4, 't'),
                          (7, 'a'),
                          (10, 'a'),
                          (11, 't')])


if __name__ == '__main__':
    unittest.main()